Instant force speed cap + deceleration (SOLVED)


In my proof of concept (For a potential game idea, just testing for now), I have a ball that rotates towards the mouse cursor. Clicking shoots puffs, which propels the ball backwards, your main method of moving.

Here is a bit of gameplay so far (Note: Walls don’t have collision yet, so please excuse that):


For this POC, when the ball is puffing puffs, I want it to slowly pick up speed, and when it stops puffing, I want it to slowly decelerate until coming to a stop. This is where I’m having issues.

See, when testing, I found out that the best way to achieve the way the ball picks up speed realistically is with a permanent force. Instant forces don’t give me that realistic feeling to the movement and also makes the ball abruptly stop in place.

My problems are when using a permanent force, the ball never stops moving. Sure, I can shoot puffs to slow it down, but I want to make it so that once the ball stops puffing, it decelerates into a halt. I’ve tried putting an object variable that increases when puffing and decreases when not that affects the speed, but it didn’t work.

Also, when continually puffing, the ball will continue to gain more and more speed. For this POC, I want to put a limit to how fast the ball is allowed to move so that he doesn’t achieve light speed just by holding down the button (This can cause glitchy interactions, like clipping through solids). I tried to put a max speed variable on the ball object (In combination with the above mentioned variable), but nothing I did worked.

Here is the code so far (The previous code for slowing down the ball and speed limit were deprecated in this snip):

So how can I make the ball decelerate and slowly stop when not puffing, and also put a limit on how fast the ball is allowed to move?

Thanks in advance ^^

(Note: The force HAS to be a permanent force since it achieves the best and most realistic movement results for my POC so far, unless there is an improved way to do it with instant forces)

You litterly have to do the same for the ball then with the puff.
The magic word is instant forces and the magic wand for it is the object variable speed
Just decrease balls.variable speed with timedelta, if you don’t shoot, or always decrease it If greater 0 and make sure you are adding more force by shooting, then you decrease.
As for speed cap, just use condition if speed of ball < cap speed to add force

Listen, I said in the post that I already tried to pull this off but failed (I mentioned that this was an earlier screenshot). Did you think that I just immediately came to make another post? I don’t want the game to be made for me, I basically got stumped again (Also, I never ask anything here before trying it myself).
I tried using the same method to move the ball as well, but I couldn’t get it to work like it needed to. That’s why I posted this (As well as getting the cap to work).

Either way, I took your advice on the cap, and readjusted the deceleration forces a little different from the puffs o achieve what I wanted, and this is the result (Note: 200 is the speed cap. I declared this as an object variable):


It works almost perfectly, but there’s one last issue to address. Notice that when the ball stops shooting, it still curves around in the direction of the cursor. I still want the ball to face the mouse, but I want it to move in a straight line relevant to the last angle it was travelling when it slows down instead of doing this awkward curvature motion. It’s not very realistic.

I feel like I know what’s going wrong here, but what I tried didn’t work (Such as trigger once). Here is the code (Point of interest is the “Slow down the ball” comment):

Any idea on how I can fix this?

You want to add ballspeed when you shoot.
So put your add force to ball into your for each puff loop.

E: I noticed that might not work.
I have to sleep, and have a look tomorrow.

I tried to put a “for each puff” loop on both events with the forces, but the bottom one just shoots the ball away really fast, and the top one just makes the ball’s movement choppy.
Unfortunately, neither solution fixed the weird curvature.

E: Oh okay

So when button is not down, store current angle once and use it for deceleration. :slight_smile:


Okay, I can’t believe I didn’t think to try that. Thanks ^^

1 Like