Question by
elijahdar · Jun 15, 2016 at 06:15 AM ·
scripting problemrigidbodymovement scriptmovepositionmoving platform
Moving RigidBody Smoothly
Hello all.
I'm trying to write a player movement script for my game and everything was working until i saw a really bad stuttering while moving.
YES, i was moving using Rigidbody.movepostition and I know using Kinematics in fixed update would fix it but I want the player to actually have physics and collide with walls and stuff. So I went on the internet and found out using AddForce might help with the stuttering/lag. but i don't know how to use it. Im really confused about all this.
Here's the code piece that's relevant to this topic:
void Update() {
float h = CrossPlatformInputManager.GetAxis("Horizontal");
float v = CrossPlatformInputManager.GetAxis("Vertical");
Move(h, v);
if (h != 0 || v != 0)
{
isMoving = true;
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), Time.deltaTime * rotationSpeed);
//playerRigidBody.MoveRotation(transform.rotation = Quaternion.LookRotation(movement.normalized)); <---- Sharp turn
}
else
{
isMoving = false;
}
}
void Awake() {
playerRigidBody = GetComponent<Rigidbody>();
anim = GetComponent<Animator>();
}
void FixedUpdate() {
Animating();
}
void Move( float h, float v) {
movement.Set(-v, 0f, h);
movement = movement.normalized * Time.fixedDeltaTime * speed;
playerRigidBody.AddForce(movement);
//playerRigidBody.MovePosition(transform.position + movement); <---- Stuttering, Possible Cause?
Comment