- Home /
Steam VR Omni-Directional Locomotion
I am trying to make an a character controller that allows the player to press a location on the trackpad and that would be the direction that they are going. This is what i have so far and it works perfectly with one problem:
Vector2 touchpad = (touchPadAction.GetAxis(RightHandSource));
Vector3 direction = new Vector3( PlayerSpeed * Time.deltaTime * touchpad.x, 0,PlayerSpeed *
Time.deltaTime * touchpad.y);
direction = transform.rotation * direction;
rb.velocity = direction ;
However, i want this to be relative to the rotation of an object. Previously i had used this:
else if (touchpad.y < -0.4f)
{
// move backwards
Vector3 forward = CurrentMovementType.transform.forward;
forward.y = 0;
forward.Normalize();
rb.velocity = ((forward * PlayerSpeed * Time.deltaTime) * -1);
}
else if (touchpad.x > 0.4f)
{
//move left
Vector3 forward = CurrentMovementType.transform.right;
forward.y = 0;
forward.Normalize();
rb.velocity = ((forward * PlayerSpeed * Time.deltaTime));
}
else if (touchpad.x < -0.4f)
{
//move right
Vector3 forward = CurrentMovementType.transform.right;
forward.y = 0;
forward.Normalize();
rb.velocity = ((forward * PlayerSpeed * Time.deltaTime) * -1);
(The first IF is missing, do not worry about that as i had reused it somewhere and cannot find it, but it follows the same format)
So the this code is relative to the "CurrentMovementType" which is one of 3 objects: left hand , right hand or face direction. It works, but it does not allow movement in all directions, only up down right and left. Not top left, top right, etc.
I like the second code allot more and i feel like i am just missing 1 piece to make it work relative to another object as currently it is just towards the direction of the Player gameobject.
Answer by PrimeSoul · Apr 10, 2019 at 01:08 PM
Just 2 minutes after posting this, i found the answer my self.
changed
direction = transform.rotation * direction;
to
direction = CurrentMovementType.transform.rotation * direction;
Your answer
Follow this Question
Related Questions
CommandInvokationFailure: Gradle build failed. 1 Answer
Gaze Pointer (Gvr reticle) seems double 2 Answers
How to access Raycast's gameObject from the Gear VR control? 0 Answers
How can I share content from my android app to user's facebook profile, in VR mode(Unity 3d)? 0 Answers
What version of unity works with the Samsung Gear VR innovator edition for Note 4? 1 Answer