I want my RigidBody2D
to do a flip when it jumps by applying an off-centre impulse to it, precisely, on a point on either of the diagonals from its centre to its bottom corners. While this might not work, depending on the transform, I'll worry about that later, as the problem presently persists, even with correct orientation, that being, it doesn't spin at all >β;β( As to its origins, I speculate two possible causes:
- I may not be fully understanding how the moment of inertia is calculated by the engine (
PhysicsDirectBodyState2D.inverse_inertia
)
- I may not be fully understanding high school physics
Anywho, here's the code:
func _physics_do(_state: PhysicsDirectBodyState2D):
if state_owner.tried_to_jump && !parent.contact_indices.is_empty():
state_owner.tried_to_jump = false
jump_force = sqrt(2 * max_jump_height * state_owner.gravity) * Vector2.UP
state_owner.apply_impulse(jump_force, (_state.inverse_inertia * flip_angle / (4 * max_jump_height)) * Vector2(-1, 1))
jump_time = -jump_force.y / state_owner.gravity
emit_signal("jump", jump_time)
The whole thing is in a state machine that I somehow got working v W v , so the functions and variables are a bit weird, as in _physics_do(_state: PhysicsDirectBodyState2D)
is a recreation of _integrate_forces(state)
and state_owner
refers to the node with the actual _integrate_forces
function. Also, here's all the calculations made by my exerted cerebrum:

Everything is pretty standard, apart from the inputs, which are:
x, which is the local co-ordinates of the point on which the impulse is applied
h, the max_jump_height
theta, the flip_angle
...and my incredible handwriting, ofcourse u///u