Smooth enemy movement

0 favourites
  • 12 posts
From the Asset Store
Be discreet and rescue your friends from behind enemy lines.
  • Hello guys I have enemy what I am doing is that every 8 seconds this enemy moves forward by 4 pixels in current angle. So I have like:

    system every 8 seconds

       enemy move forward 4 pixels

    The problem is that I want my enemy to move smoothly. I mean right now the movement is kinda jerky. It looks more like it jumps to the new position. But I want it move smoothly by those 4 pixels . How to do that? thank you

  • Look up the Lerp() function.

  • make sure you use delta time (dt) to make your game framerate independent

    Here's a link to manual

    http://www.scirra.com/tutorials/67/delta-time-and-framerate-independence

  • Rory: yeah I am trying to use it but no luck :/

    shinkan: yep normally I use it. Since this is just testing for me I did not in this case.

  • if you can use external plugins use moveto behavior

    if you can't, well you're stuck with lerp

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I would like to use lerp as I want to learn it without plugins but I dont understands how lerp will help in this case. Could you be more specific how should I use lerp in this situation

  • Here's one way to do it:

    stepMovement.capx (r99)

  • Here's one way to do it:

    stepMovement.capx (r99)

    Thank you I have to study it more because it seems complicated in this example.

    However I tried to understand lerp by my way, I think I finally understand little bit why is it useful. But still no luck.

    Now I have every 8 second, enemy1 move forward and I Put in: lerp(enemy1.Y,enemy1.Y+50,0.8*dt)

    but the movement is still not smooth and it still looks like it is jumping to that position :/

  • lerp is a function to make easy for you search and walk a path between two points.

    if you want a smoothly movement, you'll need acceleration and deceleration, or it will jump between pixels with the instantly maximum speed.

    Another thing, if you set your project to use pixel rounding, it will keep the old position then jump one pixel when the object reach this pixel distance, so, it can show an animation not much smoothly.

    If it's your case, just use linear Sampling.

  • Thank you but could some of you be that specific and actually past a code example here? just take mine and reedit it. I am not programmer so I am totally lost :) sorry for so many questions.

  • Here's one way to do it:

    stepMovement.capx (r99)

    So I think I finally understood this and got it work. Only problem is that when you start a game it immediately starts to move. I need to wait about 4 seconds on start of the game before all this moving

  • Ups sorry I figured it out. What i did is:

    I set variable can_move for enemy. Default value is 0.

    system on start of the layout system wait 4 seconds. After the set value can_move to 1.

    And then in condition which handle lerp movement I have if can_move = 1 then do the rest :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)