- Home /
Adding impulse force cancels out gravity force on collisions.
I trying to move my player using AddForce. I don't like the feel of using ForceMode2D.Force because it takes a while for the player to get up to speed and it seems to be constantly accelerating. I want to use ForceMode2D.Impulse because the movement is snappy and instant. However, when the player is falling or jumping and collides horizontally with a wall they don't fall but are stuck there against the wall (until I let off the inputs). If I use ForceMode2D.Force I don't have this issue the player hits the wall and will fall like expected.
I am applying gravity using AddForce as I want to be able to switch the direction of gravity.
Is there a way I can either:
1/ Make ForceMode2D.Force feel instant and snappy without constantly accelerating?
2/ Have ForceMode2D.Impulse not cancel out other AddForces?
If you attach a rocket to a person and then fire them against a wall would you expect them to fall?
The friction of the wall and body are the problem its otherwise behaving as expected. If you want it to slide down the wall reduce the friction and it will.
Otherwise you are basically saying "why don't my photos fall down when I nail them to a wall?"
How about instead of having the impulse happen whilst you are holding a button down you instead create a coroutine that triggers a single impulse or a short impulse over a period of time?
Answer by julianbrezon · Nov 29, 2020 at 04:12 AM
If it only happens on collisions, try this:
Create a new physics material in your project
Set both frictions to 0
Apply material to wall you're colliding with
See if you still stick to it.
That is one solution that is working for the walls but I have another scenario that it doesn't work for I forgot to mention. When I switch the gravity on the player and they are already falling, the Impulse force makes the gravity switch instant (like if i were to immediately change the velocity). If the player's gravity is the [0, -9.8] and I switch it to [9.8, 0] then the Impulse force will stop any movement on the Y axis and immediately transition gravity the the X axis. With the Force$$anonymous$$ode2D.Force, the player will keep their Y velocity from the old gravity as well as take on velocity from the new gravity causing them to fall in a parabola motion. I was hoping to keep that because it feels more realistic.
Your answer
Follow this Question
Related Questions
How do i make the Impulse i give to my Player not be lowered by acceleration of gravity? 1 Answer
How can you make gravity to not have any acceleration but with const velocity? 1 Answer
Very simple water bouyancy script not working? 1 Answer
Vector3 Parameters and AddForce Not Working Out 1 Answer
How to change gravity's direction on a single gameobject? 0 Answers