|
I have a script that handles rotation and movement for a character rigidbody. It rotates properly, and moves correctly in one direction. I'm using Input.GetAxis("Horizontal") to determine if the character should move left or right, but when applied to a Translation, the character ALWAYS moves in the positive direction, even when the input is negative. Any ideas? }
(comments are locked)
|
|
You use the same input values for rotation and movement at the same time. Is that intentional? Might it be that your game object gets rotated in such a way that the movement will always happen in only one direction? Try commenting out the rotation code and see what happens to the translation. Yeah, that was the problem. Both of those things are dependent on the same input axis though. Any ideas how I could go about getting them to play nicely with each other?
Aug 01 '12 at 11:26 AM
Razion
It depends on what you want to do. So what do you want to do?? If you want your moveSpeed to be constant you can do something like this: If you want it to stay dependent on the input axis range, you can just take the absolute of that value. Something alont the lines of:
Aug 01 '12 at 11:38 AM
senad
That's the problem, though. Using an absolute value for either translation or rotation will only allow movement/rotation in one direction. When horizontal = 1, I want to rotate to face right (which works), and when it's -1, I want to rotate to face left (which also works). When I attempt to add translation (negative for left, positive for right), I always move to the right because my rotation is throwing me off. (This is a sidescroller) Using Vector3.forward isn't an option as far as I know, because my rotation takes .5 seconds to go from 0 to 1 or -1 for the sake of animation purposes.
Aug 01 '12 at 07:45 PM
Razion
Yes, so as I understand it, your rotation and translations add up and let your char move in the same direction each time. So what I think you should do is always use positive translation values and leave the rotation as it is. Maybe I am understanding you wrong??
Aug 02 '12 at 08:37 AM
senad
I see. :) If it is a side scroller, all you want to do is move your char left or right in world space. There is no need to use local model space. Just add the parameter "Space.World" to your transform.Translate() call. Then the rotation will have no effect on your translation. :)
Aug 02 '12 at 09:24 AM
senad
(comments are locked)
|
