[SOLVED] Decelerate a bullet


#1

Greetings,
In this proof of concept I’m working on has a ball that points towards the cursor, and shoots little puffs in the direction it shoots in, pushing it backwards every time it shoots a puff.
I want the puff to start off fast, but gradually slow down until it comes to a stop. This is what I have so far, but it doesn’t work. The puffs just fly forever:


I already know that I have this wrong, but I have no idea how to accomplish this.
How can I make it so that the puffs start out with a fast force, but slowly decelerate until stopping?
Sort of something like this (I opened the Construct 3 free trial with the bullet shooting example and made some modifications):

Basically, how do I do the thing in the GIF in GDevelop?
Thanks


#2

Try something like this
in a foreach puffs
if puff Force > 0
set puff Force = CurrentForce -= 10
then replicate to the opposite direction


#3

Okay, I tried it out, but unfortunately, nothing happened.


Your suggestion implies to me that there is a way to check the current force of an object rather than using a variable. Is that possible?


#4

Without variable just compare Two numbers the play with your bullet properties like ForceAngle or ForceLenght


In order to add this compare condition you need to go to the Other Conditions tab and look for Other then select compare two numbers


#5

Okay, I’ve changed the code up, and this is what it looks like:


However, for some reason, instead of slowing them down, the puffs just speed up dramatically and zoom away once spawned. Is there something else I’m missing?


#6

You are adding permanent forces, without trigger once.
You want to use instant forces


#7

Like this?


This still does not work. The puffs just continue traveling without slowing down.


#8

Because you still use permanent force on creation. You can delete the force on creation, and replace it with set var speed of bullet to 100 (Your max bullet speed)
Also trigger once doesn’t work on instant forces.
So your for each loop cannot have trigger once,
and instead you set the force to it’s variable speed and also reduce the variable speed
Your condition needs to change to var speed of bullet > 0


#9

Okay, I tried this out:


However, they still don’t decelerate at all. Also, they no longer shoot in the direction of my mouse anymore. Did I miss something?


#10

because you move them with 90 speed. (100-10)
you need to have add force and also subtract 10 from the variable as events.
also you need to specify the angle


#11

I tried out the code:


New problem though, the puffs are deleted as soon as they spawn. I disabled the delete action, and it turns out that the puffs aren’t moving at all.


#12

looks like you do not subtract from your variable speed, but you set it to -10


also 10 per frame is fast deceleration. consider subtracting like 1


#13

The puffs are now decelerating just like I wanted them to. Thanks.
However, I have a new problem. I want the puffs to shoot in the direction the ball is facing, not towards the mouse cursor. When I rotate the mouse fast, the puffs shoot in the direction faster than the ball can rotate.
The ball rotates towards the mouse, and the puffs fly straight out of the ball’s face in the direction it’s facing. As of right now, the puffs shoot in the mouse’s direction. How can I change this back to firing from the ball’s angle rather than the mouse’s?
Also, I’m using TimeDelta() instead since it’s better to use. I’ve got the puffs at the right speed I want with some adjustments.


#14


#15

Okay, it works perfectly now. Thanks ^^