How to add acceleration to character body2d

If you assign target_velocity = to a value based on inputs, like the sample below, then it will stop when there are no inputs pressed, because the target velocity will be 0 * SPEED which equates to zero. Could you share how you are handling inputs currently?

1 Like

I’m not using inputs; I want the player to move when they punch like impulse but then after I got the drag for this to work, I needed acceleration to make it better. I didn’t want acceleration for movement I wanted it for an impulse for a punch.

Impulses don’t have acceleration, they are a one-frame addition to velocity. How do you see acceleration helping in this? What are you experiencing about your current punch-velocity-drag implementation that you want to fix?

1 Like

impulses do have acceleration! right? if only a very little bit surely, they do. Well, I think impulse would look or feel better if it had a little bit of acceleration. When I set up impulse for the first time it would set a speed and then go to 0 but example: it might go from 200 to 190 to 180 to 170 until it hits 0, it does this smoothly so it doesn’t look like someone throwing a 2d punch instead it looks like my character is sliding from one point to another

you there

I’m just not sure I am understanding your example, it sounds like friction/drag after a impulse to me. Impulses add to velocity, not acceleration, of which velocity may decay over time without another impulse/force.

Maybe adding some camera shake or other juice would help out?

Have you ever slid a nearly empty jug of milk? The liquid sloshes around and accelerates the jug mid-way through moving, I feel like that’s the effect you’d end up with by adding acceleration to the mix.

1 Like

but why does it look so weird than : (
after some thinking, I think I can put it into words better.

The punch is moving at one speed from the start to finish kinda. I think the term is ease? easing from value to another.

But things in real life slide at different speeds, I slid something, and it was pretty fast and then stopped really quickly. The punch would have slowed down slower, the thing I slid was not slowing down at the same past the whole time it was sliding. This is why my characters punch feels weird I think.

based on this example, I remove acceleration (since it isn’t part of the equation), increase the friction/drag from 300; depending on your game’s scale relative to pixels. Then greatly increase the added velocity.x, at least half as much as the friction/drag value

1 Like

Thank you, I’m finally happy with my games dumb punch and can move on to the afterlife. I will be putting you in my will and overall thanks for sticking around to help me through all my bullshit

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.