-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix push bodies #470
Fix push bodies #470
Conversation
caf6f10
to
8193e7b
Compare
There are a few problems with the impulse application logic. Impulse StrengthCurrently the impulse strength doesn't vary based on whether the player is walking into the object, or sliding almost perpendicular to the object. This one's a fairly simple fix - just change the strength calculation to be based on the dot-product between the player velocity and the surface normal as follows: var strength = p_velocity.dot(-with.get_normal(0)) * push_strength_factor This feels more natural when walking into objects in glancing blows vs straight on. Low Mass BulletsAnother problem which is more challenging is that if you try pushing a RigidBody3D with a low mass (0.0001) then it will fire off faster than a bullet, as the "impulse" results in a massive velocity. You want heavier objects to be more resistant to moving, but you don't want lighter objects to be affected so much that they move faster than the player. I'm not sure how to fix that problem. Relative-Velocity ImpactsA third problem is with reference-frames. If the player is in a train moving at 10m/s and just brushes up against an object, the p_velocity of the player will be around 10m/s, even though the velocity "at the point of contact" is tiny. The solution is to change from using the players absolute velocity, to instead use the relative velocity between the player and the RigidBody3D contact point. The problem is it seems to be difficult to ask Godot what the contact point velocity is. There's |
8193e7b
to
37cb50c
Compare
@Malcolmnixon sorry for the late response. Indeed tricky issues, I've adjusted the logic somewhat. Impulse StrengthThe impulse strength change you suggested makes sense so I applied that as you suggested. Low mass bulletsThe issue with low mass bullets is much more tricky. We're talking about transfer of energy as we're hitting an object. So our mass (which doesn't exist in CharacterBody3D) times the velocity of impact determines how much force we're impacting the object with. The lighter the object, the more the resulting velocity is of this energy being applied to the object. However more is going on than that simplistic highschool view of physics as generally bumping into small objects in your living room, doesn't sent them flying through the room like crazy. I'm not to read up on this so I'm also not sure what the missing ingredient is and how to properly calculate this transfer of energy. I might see if I can fine some time looking into Godots physics engine because this is no different from what the internal code should be doing when two rigidbodies collide. Relative-Velocity ImpactsThe relative velocity thing is an issue, |
37cb50c
to
7adb860
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works very nicely now.
Re-implement being able to push bodies around with the player body
Fixes #467