- Home /
Two and fro movement of the object at waypoints
I am having the problem in my project, where the object is move two and fro at the waypoint where she has to be stationary. Here is a bit of my code:-
if(checkcond == 0)
{
if(move==1)
{
imageBox.active = false;
velocity = moveDirection.normalized * speed;
girl.animation.Play("walk");
checkcond=1;
print("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
//print(girl.transform.position.x);
}
}
else
{
print("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
velocity = Vector3.zero;
imageBox.active = true;
girl.animation.Play("talk03");
}
rigidbody.velocity = velocity;
transform.LookAt(new Vector3(customer.transform.position.x,transform.position.y,customer.transform.position.z));
//transform.LookAt(target);
Please help me. Thanks in advance.
i dont get ur question can u explain wat shd happen!! the character should move to and fro or stay statioinary!!
ur code jus calculates the velocity and doesnt seem to use it anywhere
Answer by senad · Dec 19, 2011 at 10:37 AM
So the code looks good to me. If your move variable is zero, the velocity will be a 0 vector. If you add it later on to the position, I would expect the entity not to move.
What you need to do is a litte debugging. You need to check, if the checkcond if-statement is entered, if the move variable is zero and if the zero vector is actually assigned to the velocity.
If this is all the case, you need to check if the velocity is still zero later when you use it to calculate the position. If not, you need to check why not.
Your answer
Follow this Question
Related Questions
I'm trying to make AI that walks (and faces) towards a waypoint 1 Answer
store the user touch input 0 Answers
Move object along waypoints, but affected by gravity -1 Answers
Multiple waypoint solutions 2 Answers
Kind of Lag in movement 2 Answers