- Home /
problem occur when moving to the hit.point
*this thread isn't connected in any way to the previous one.
there're 2 problems I encouter : 1. When I move to the hit.point so it moves fast at first, and then gradually slowing its speed when im near the hit.point, i want it to go straight with its speed without slowing or anything - i thought because of yield; but without yield; it won't work :/
When I'm standing on the terrain which its surface's height is really high(like a mountain) and moving to a low height so it like flies to that hit.point and not 'walks' to it..
private var speed = 1; var object : Transform; var hit : RaycastHit;
var movePosition : Vector3; var moving : boolean = false; animation.wrapMode = WrapMode.Loop;
function Update(){ var ray = Camera.main.ScreenPointToRay (Input.mousePosition); if (Physics.Raycast (ray, hit, 3000) && hit.collider.tag == "Terrain" && Input.GetButtonDown("Fire1")) { if(moving) { movePosition = hit.point; }else{ movePosition = hit.point; MoveObjectToString(); } } } function MoveObjectToString() { moving = true; while(Vector3.Distance(movePosition, transform.position) > 0.1){ animation.CrossFade("walk"); var controller : CharacterController = GetComponent(CharacterController); var direction : Vector3 = movePosition - object.position; controller.SimpleMove(direction * speed); yield; } animation.CrossFade("idle"); moving = false; }
Answer by Tetrad · Jun 19, 2010 at 11:07 PM
The reason you see the speed problem is because you're not normalizing your direction vector.
Change this line
controller.SimpleMove(direction * speed);
to this:
controller.SimpleMove(direction.normalized * speed);
You're so right! now I releaize that what a guy told me really needed to be re-considered about using .normalized.. Thank you Tetrad! 1 problem left now, to make a real move!
Solved. also adding if((CollisionFlags.CollidedBelow) != 0){ is useful.
Your answer
Follow this Question
Related Questions
How do I make the nose/whole of my spaceship move? 2 Answers
Make Objects to ricochet 1 Answer
How Can I Make The Parkour Moves Move Smoothly Instead Of Instantly Teleport? 1 Answer
Gui problems. 1 Answer
Mecanim walk to target position 1 Answer