I have 3 sprites A, B, and C.
A and C are objects…
B is Enemy sprites… so the design is below. I need B to move continously between A and C.
A———-B———-C
I use the below method in an Update method. So that methods gets called for each frame.
ABcollision
{
if(Aistouched == YES)
{
Bvelocity.x = 5; /// moves my sprite B right side
}
}
CBcollision
{
if(Cistouched == YES)
{
Bvelocity.x = -5; /// moves my sprite B right side
}
}
My update method to update velocity:
b2Vec2 dins = dinobody->GetLinearVelocity();
dinobody->SetLinearVelocity(Bvelocity);
The above code makes my sprite B move left and right only once.
I believe that the problem when it only works once is because you never reset your BOOLs from what I can tell.
AistouchedandCistouched. Try addingAistouched = FALSEright after your set theBvelocity.x = 5;and same for C.