0 Favourites

Set speed of movement without using any behaviours?

This forum is currently in read-only mode.
  • When I set condition "Move at angle", for example, or "Rotate at angle", the object quickly jumps to point. But I want it moves smoothly to see his movement.

    How to make that? How to set his speed (i suppose) WITHOUT using any behaviour?!

    Thanks!

  • Use TimeDelta system expression.

    It is basically time between two frames. If you multiply your speed variable, say, PlayerSpeed, with TimeDelta, the player will move by the amount of pixels he would have made in that time (frame).

    Move at Player.Angle for Player.Value('Speed')*TimeDelta

    Try it out.

  • Mipey, i think he means acceleration. to make acceleration, you have to always set your object to .x+'speed', and have other events which gradually change the speed value.Only multiply by timedelta if you want your game to be framerate independant (ie. Lag which skips frames instead of slowing the entire game down.) timedelta has nothing to do with speed of movement, it's only there to account for varied game framerates.

  • Mipey, i think he means acceleration.

    I pretty much believe its she, and to the point using Time Delta is good to make it look same on different Refresh Rates.

  • Why not use a behavior? That seems the obvious thing to do. The bullet behavior would be suitable. Or, use Mipey's suggestion, which is basically to move the object a small step every tick (which is what the behavior does).

  • Thanks to all for help !

    Timedelta works properly. I've set both acceleration and speed of object's movement and I'm satisfied with the result

    About behaviours - I use it sometimes, but there're situations when better to make it yourself than use pre-written behaviour.

  • Sometimes I like to make custom movement for things that would otherwise work perfectly with a behaviour... usually because it's fun xD

    ~Sol

  • I still have some questions

    For example, i want to make that the sprite moves every 64 pixels (as grid movement but not using this behavior). I set "when press Right arrow key then move 64 pixels at angle 0" - sprite jumps these 64 pixels. Then I add Timedelta and it smoothly moves, but not exactly 64. It moves while i press key, but when i released - it stops in random place.

    How to make that the sprite moves smoothly and on the same number of pixels? Another words - grid movement but without using any behaviors?...

    What do you think?

    p.s. this is my unsuccssesful attempt - http://willhostforfood.com/access.php?fileid=64568

    p.p.s sorry for my bad english

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • i want to make that the sprite moves every 64 pixels

    How to make that the sprite moves smoothly and on the same number of pixels?

    Does this work for you, maybe? http://dl.getdropbox.com/u/529356/gridmove.cap

  • In that case you have to set it up to keep running until it's made 64 pixels. Make an event that is run whenever a private variable contains the right value.

    Like this (assuming you have a private variable 'Status'):

    //triggering event
    +Right Arrow is pressed
    +Player('Status') = "Idle"                           // Only move the player if it is not already moving
    Player('Status') = "MoveRight"                // Tell it to start moving
    
    //actual moving event
    +Player('Status') = "MoveRight"                   //check if the player is set to move right
    +Player.X < Player('OldPositionX')+64            //Keep moving until the goal is reached
    Player.X = Player.X + Player('Speed') * TimeDelta
    ++Player.X > Player('OldPositionX')+64          //Whoops, a little over the goal; it means it has reached it
    Player.X = Player('OldPositionX') + 64          //This is to round the player's position up
    Player('Status') = "Idle"                //Tell it to stop moving
    

    Player('OldPositionX') = Player.X //Remember the new position

    [/code:12glmkv3]

    As always, + are conditions, ++ subevents, > actions, >> subevent actions

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