- Home /
How to avoid speed slowdown in case of controller.Move();
Hi everyone, I think it is quite simple question, but I am stuck. My character moves from point to point, but problem is that speed is slowdown when it comes closer to the point. How to make movement more equable?
function myMove(mytarget: Vector3){
var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded) {
moveDirection = (mytarget-transform.position).normalized;
moveDirection *= speed;
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
Answer by aldonaletto · Sep 11, 2011 at 03:22 PM
I suspect the difference in heights between the target point and the character is causing this: when moveDirection is normalized, a high Y component will reduce the horizontal velocity component. With a small change, this vertical component can be ignored prior to normalization, what should result in a constant speed:
function myMove(mytarget: Vector3){ var controller : CharacterController = GetComponent(CharacterController); if (controller.isGrounded) { moveDirection = mytarget-transform.position; moveDirection.y = 0; // ignore vertical distance before normalization moveDirection = moveDirection.normalized * speed; } moveDirection.y -= gravity * Time.deltaTime; controller.Move(moveDirection * Time.deltaTime); }
Your answer
Follow this Question
Related Questions
How can I get my character to move and strafe relative to the way its pointing? 2 Answers
Character Controller not moving model at all, but acts like it is? 1 Answer
The controller.move does not work correctly 0 Answers
Character Controller / Charactor Motor has no inputs? 1 Answer
Character too floaty after jumping and grappling.,Grapple too floaty 0 Answers