0

Hey guys,
I'm trying to make an AI character perform a pattern movement when a certain action occurs rather than have him do it all the time. I call two different methods, one to move him left, then move him right, the problem is the first method is still active when the second is called and it cancels out the movement and he stands still. Any suggestions??

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by nmaillet
0

How is that method still "active"? Are you creating a second thread for each movement action? Generally, if you want to explicitly move something, you would have a method set the object's speed, then the actual movement is handled each step through the main game loop. Something like this:

function move_left() {
    hspeed = -1.0;
    ...
}

function move_right() {
    hspeed = 1.0;
    ...
}

function game_loop() {
    ...
    obj.x += obj.hspeed;
    ...
}

You also shouldn't be incrementing your speed, you should be setting it. With so little information, I can't really give you any more advice. Please post some code or, at least, some details on how your handling movement.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.