Hello Guest

Author Topic: Rotating Sprite on Touch and Drag  (Read 5396 times)

amit.r007

  • Newbie
  • *
  • Posts: 4
    • View Profile
Rotating Sprite on Touch and Drag
« on: June 17, 2014, 11:22:25 am »
Hi Unikron,

In my 2D game I have a circular sprite which I want to rotate as per touch input. I want to rotate that 2D sprite on z- Axis, say like a 2D Car steering (x and y fixed) according to the touch and drag of a finger/thumb.

Please help me regarding the same.

Thanks,
Amit

amit.r007

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Rotating Sprite on Touch and Drag
« Reply #1 on: June 18, 2014, 12:31:03 pm »
Any thoughts on this ?? :)

rakkarage

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Rotating Sprite on Touch and Drag
« Reply #2 on: June 18, 2014, 01:33:56 pm »
here is some touchScript (http://interactivelab.github.io/TouchScript/) code for panning
you could do something similar but change rotation instead of position maybe
Code: [Select]
private void HandlePanStateChanged(object s, TouchScript.Events.GestureStateChangeEventArgs e)
{
if (Utility.Paused) return;
Menu.Instance.Close();
switch (e.State)
{
case Gesture.GestureState.Began:
case Gesture.GestureState.Changed:
SimplePanGesture g = (SimplePanGesture)s;
if (g.LocalDeltaPosition != Vector3.zero)
{
GameCamera.transform.localPosition -= g.LocalDeltaPosition / GameCamera.ZoomFactor;
}
break;
case Gesture.GestureState.Ended:
Spring();
break;
}
}