Pathfinding | Decelerate and Accelerate on Touch?

0 favourites
  • 10 posts
From the Asset Store
Units do not overlap each other and use different ways if there are several free ways.
  • Hello,

    I've got a simple setup here; I move the PlayerCar object when the right Pedal is touched.

    Now unfortunately there aren't any 'Decelerate' or 'Accelerate' actions?

    So right now it abrubtly halts and moves. I'd like it to decelerate when GasPedal isn't touched, and accelerate to its MaxSpeed when it is touched.

    I'm sure there's a simple solution for this, I just couldn't find it.

    Thanks!

  • You can change pathfinding max speed like this:

    Is touching GasPedal
    	Set pathfinding max speed to min(Self.Pathfinding.MaxSpeed*1.05, 200)
    
    Else
    	Set pathfinding max speed to Self.Pathfinding.MaxSpeed*0.95
    
  • Hiya!

    Thanks. I inserted the code, but upon game start, the PlayerCar moves a bit forward, stops, and isn't responsive to touching the GasPedal?

    Also, what does 'min' and '1.05' mean? 200 is the max speed?

    Thanks.

  • Ok, multiplying by 1.05 is not a good idea - when the value drops too low, it takes a long time to increase it.

    Try this:

    Is touching GasPedal
    	Set pathfinding max speed to min(Self.Pathfinding.MaxSpeed+4, 200)
    
    Else
    	Set pathfinding max speed to max(Self.Pathfinding.MaxSpeed-4, 0)
    

    min() expression will choose the smallest of two values, so yes, 200 is the highest possible speed.

    max() will choose the biggest of two values, in this case it will not allow the speed to drop below zero.

  • you can also use lerp function: Set max speed to lerp(currentSpeed, targetSpeed, dt*4)

  • Try this:

    > Is touching GasPedal
    	Set pathfinding max speed to min(Self.Pathfinding.MaxSpeed+4, 200)
    
    Else
    	Set pathfinding max speed to max(Self.Pathfinding.MaxSpeed-4, 0)
    

    Ah yes cool that works! Thanks!

  • dop2000 Basically I'm trying to get the PlayerCar to follow a simple route to the end of the level.

    Currently I'm using pathfinding but it doesn't work as expected. I just want the PlayerCar to follow a line/route. I could use the MoveTo behavior plugin or something similar like manually programmed but then it won't take a smooth turn, instead it abrubtly changes its angle.

    Is there any simple way to make a sprite follow a route with the on Touch GasPedal 'system' you posted? And that it will take corners smoothly?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try Bullet or Car or Custom Movement behavior to move from point to point.

    Here is a demo I made with Bullet:

    dropbox.com/s/s58syrvy3xa2rg9/BulletMoveWithWaypoints.capx

    .

    Also, take a look at Spline behavior:

    construct.net/en/forum/extending-construct-2/work-in-progress-addons-30/behavior-rex-spline-114539

  • Hiya,

    Thanks man! That works great and it's so simple.

    One thing that happened to me, was that when I changed the starting angle of the Car to anything but 90 or 180 degrees the Car would 'jump' to either 90 or 180 degrees angle and start rotating towards the first waypoint from there.

    Fortunately I was able to 'fix' it by putting the Every tick line below the Space bar key down line.

    Not sure why it works like that but it does.

    Anyway another medal for your help!

  • Yes, that was the right solution. It's always recommended to change bullet speed before changing bullet angle.

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