-1
\$\begingroup\$

I'm trying to move my Character on the world's XYZ Axes, but how do I get them?

I'm trying to do this because my Player is sort of a Sphere and is rolling around, so its xyz directions are rotating.

I thought I can fix this if I make it move with the world's xyz.

Does someone know how to do this, or another way to fix this problem?

This is my current code to move my olayer object:

    public float playerSpeed = 20;
    
    public float verticalInput;
    public float horizontalInput;
// Update is called once per frame
void Update()
{
    verticalInput = Input.GetAxis("Vertical");
    transform.Translate(Vector3.forward * Time.deltaTime * playerSpeed * verticalInput);

    
    
    horizontalInput = Input.GetAxis("Horizontal");
    transform.Translate(Vector3.right * Time.deltaTime * playerSpeed * horizontalInput);
}
\$\endgroup\$
1
  • \$\begingroup\$ So you just want to translate the sphere by +/- values on each of the X/Y/Z axis when the player hit the arrow keys (plus two other keys for Y)? \$\endgroup\$ Commented Oct 5, 2022 at 18:11

1 Answer 1

1
\$\begingroup\$

This question does not demonstrate research effort.

Just visiting the documentation page for the method you're using, Transform.Translate, would show you that you can pass a Space.World argument to apply the transformation in world space, like so:

transform.Translate(
    Vector3.forward * Time.deltaTime
    * playerSpeed * verticalInput,
    Space.World
);

Please be sure to read the documentation for the methods you're using, and you'll be able to find your own answers faster next time.

\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.