- Home /
Help with plat-former character rotate
i have a modeled character and a move script with ground detection but i want to know how i could make a smooth turn for right to left and left to right when using the arrow keys thanks
I would take a look at the Unity '3D Platformer' demo project. I seem to remember is having this kind of turning rotation.
http://u3d.as/content/unity-technologies/3d-platformer-tutorial/3yF
Try creating a animation to manage the transition? The viewer will then find the turns much smoother.
Answer by CeejayZSmith · Dec 07, 2012 at 12:27 AM
ive done it guys if anyone whats to know what i did is i put 2 gameobjects on the ends or the map called rightTarget and leftTarget then i gave them this code:
var player : GameObject;
function Update ()
{
transform.position.y = player.transform.position.y;
}
then i put in the character script if the button d is press transform.LookAt rightTarget and the same for the a button
That's.. original :)
Two things spring to $$anonymous$$d;
The code above will snap the Player to the end of the map he's turning towards. Which means that every time he turns he will snap back to the LookAt target position.
If you just used regular LookAt(), then that isn't smooth at all.
I would check out Ben's suggestion which is what I think is used in the link I gave.
Alternatively, if you want to use a smooth LookAt(), I would recommend a tutorial on Quaternions written by the guys here on Unity Answers. It can get quite advanced so best to learn the basics first.
Link: http://unitygems.com/quaternions-rotations-part-1-c/#Quaternions
Good Luck!
would you say i should use Quaternion.Lerp? i have used Vector3.Lerp but im not an expert
Personally, for this purpose I wouldn't use any kind of LookAt but ins$$anonymous$$d go with the animation suggestion above.
I would learn the basics first, then worry about the icing on the cake like this kind of thing. Download the demo project, there's a lot you can learn from it in general. You might find you start co$$anonymous$$g up with your own ideas of how to achieve things.
However, to create a 'turn left' and 'turn right' animation for the Player, you can use Unity's Animation tool. You would just need to create a 180 deg turn for both directions, then play the appropriate one depending on which key you clicked.
Good Luck.