- Home /
Set the move touchpad (in DualTouchControls , Standard Assets) moving direction relative to the player rotation
Let me explain the problem.
I got a camera that rotates around the player;
I move the player using the move touchpad which is included in Standard Assets (in dualtouchcontrols)
Everything works but if the player rotates a full 180* the controls on the touchpad are the same. For example if I wanna go down I have to press the same button but , having the camera rotated 180* , it seems that I'm pressing the up button.
What I really want is a system in which the move touchpad direction is relative to the player rotation
The touchpads just calculate your movement on the area and pass it into the input axis.
Something like this might be what you are looking for.
public Rigidbody body;
public float speed;
private float vertical;
void FixedUpdate()
{
vertical = Input.GetAxis("Vertical");
body.velocity = transform.forward * speed * vertical * Time.fixedDeltaTime;
}
So you suggest putting the Vertical axis into an update function?
Sorry , there was a misunderstanding. (by me)
I got the following code
void FixedUpdate ()
{
//$$anonymous$$ovement and rotation towards the movement direction
vertical = CrossPlatformInput$$anonymous$$anager.GetAxisRaw ("Vertical");
horizontal = CrossPlatformInput$$anonymous$$anager.GetAxisRaw ("Horizontal");
Vector3 playermovement = new Vector3 (horizontal,0f, vertical);
playerbody.AddForce (playermovement*speed);
}
It is using the default assets touch pad (as you know). I tried creating the body.velocity but it didn't work. By the way this is the player movement script , not the touchpad .
Forgot to mention, quickest solution would be to rotate the pad with the player, or alternatively calculate the movements relative to the rotation.
Tried to rotate the pad but it doesn't work. It will just remain the same (in the movement).
How could I calculate the movements relative to the rotation? I thought about using only the horizontal axis (in playermovement) and , once the horizontal axis is activated , vertical = 1.
Vertical will use the playercamera.transform.rotation.y... What do you think?
Answer by ma22be61 · May 13, 2017 at 11:11 PM
I will explain my problem a bit better. I got a touch pad which moves the player around correctly. The problem is that , when the camera rotates , the touchpad doesn't get "updated" and rather than going forward the rotation of the camera it just does the same thing independently.
Your answer
![](https://koobas.hobune.stream/wayback/20220612121907im_/https://answers.unity.com/themes/thub/images/avi.jpg)