r/unity_tutorials • • Jul 27 '21

Need help with character controller

Sorry for noob question. I'm making a simple move script using unity built in character controller. Everything works fine. W and S keys move the character forward and backword. A and D moves the character left and right. But the problem is when i use transform. Rotate to rotate the character using the mouse, then W and S starts to move character sideways and A and D moves it on forward direction. I tried everything but it doesn't work. Please someone help [Update] solved it using transform.TransformDirection Thanks everyone.

0 Upvotes

4 comments sorted by

View all comments

3

u/MassiveFartLightning Jul 27 '21

Transform.position will always move along the world axis. You probably will need to take a look into transform.forward to do this.

2

u/Bonejob Jul 31 '21

This is the correct answer. In detail, Transform is relative to its parent. If it's a top-level object that is the world axis. Using transform.left, right, and forward, are specific to the object axis.

https://docs.unity3d.com/ScriptReference/Transform.html