AnswerBun.com

How can I get the basic Unity player controller to move based on a gameobjects rotation?

Game Development Asked by 1234567890 on November 13, 2020

I am making a basic movement script based off of the built in playercontroller in Unity. I am trying to get the Player gameobject to move forward based on its own rotation (i.e. if it is rotated to 90 degrees, it will go forward in the direction it is facing and not based off of its position values), but I can’t figure out how to change it.

How can I do this?

EDIT:
I figured it out. I just had to multiply the playercontroller’s movement by player rotation.

One Answer

I think what you need is the value transform.forward This is a normalized vector that will always point in the same direction as the object's blue arrow in the scene view. Feeding this into the character controller's Move method will move the object forward, regardless of rotation.

Do note that the character controller is only designed to function with an objective 'down' aligned to the y-axis. This means that if you rotate on any axis but the y-axis, it can lead to some strange results.

Answered by Weckar E. on November 13, 2020

Add your own answers!

Related Questions

Compute shader: Property at kernel index is not set

1  Asked on November 2, 2021 by glen-pierce

   

How can I cast light onto a sprite in 3D environment?

1  Asked on November 2, 2021 by vern-rowan

   

How to run skactions randomly

0  Asked on November 2, 2021 by why25

   

AntiGravity Vehicle?

1  Asked on November 2, 2021 by roswell

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir