Move the Character in World Space CharacterController.Move(MoveVector) Multiply MoveVector by DeltaTime MoveVector *= ltaTime Multiply MoveVector by MoveSpeed MoveVector *= MoveSpeed Normalize MoveVector if Magnitude > 1 if (MoveVector.magnitude > 1) MoveVector = Vector3.Normalize(MoveVector) Transform MoveVector to World Space MoveVector = transform.TransformDirection(MoveVector) I guess it may help to explain the motion. Transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(new Vector3(rotX, 0, 0)), ltaTime * rotSpeed) If (Mathf.Abs( - targetH) > 0.1f)įloat rotX = Mathf.Abs(Mathf.Abs(-targetH)/maxDist) * ( > targetH ? -1 : 1) * -maxAng Vector3 diff = transform.position - lastPos Using UnityEngine using System.Collections public class TiltingGameObject : MonoBehaviour If it is moving up at half maximum vertical speed, it will return 22.ĮDIT: Took me a bit, but I have some test code that seems to do what you want it to do. IF the object is traveling downwards at maximum speed, t$$anonymous$$s will return -45. Mathematically calculate your rotation based on speed:įloat rotX = (verticalSpeed / maximumVerticalSpeed) * 45 I know there is a description, but according to the posts in both areas there doesnt't seem to be much of a difference. PS: Sorry if t$$anonymous$$s should really be posted on forums.unity rather than answers.unity I am still a little confused about the difference and I only made an answers account. lerAngles = new Vector3( + xRot,, ) įigured I would just post and see if anyone knows of a better solution. Here is the code I am using: if (MoveVector.x != 0 || MoveVector.z != 0) I tried just setting an angle until it reaches the height, but with small angles it starts freaking out and when it goes up right before it gets to the height it is a little jerky. What I am trying to figure out is how to handle the pitch rotation so it slowly angles to some angle like 45 then back to 0 when it gets close to the target height. Transform.rotation = Quaternion.Slerp(transform.rotation, targetAngle, ltaTime * TurnSpeed) So here is my code for angling the object just for yaw: if (MoveVector.x != 0 || MoveVector.z != 0) I also have a target angle w$$anonymous$$ch is simply the yaw. There are only 3 set heights -20, 0, and 20 so it doesn't do anyt$$anonymous$$ng different if you $$anonymous$$t up or down multiple times. When I $$anonymous$$t a key I set a target height, so if it's at 0 to start and I $$anonymous$$t up the target height is say 20. That code is pretty simple and works fine so hopefully no need to post it. I have an object with a move vector and based on it's move vector, move speed, and angle it moves.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |