A mathematician will probably think this was a silly question, but I'm not one and I'm in need of help :D
I'm working in Godot and with its RigidBody2D
s (objects that have automated physics behaviour).
I want to create a spring of type RigidBody2D
(the 'springiness' is not the only function of this object).
I'm at the point in code where this spring and another RigidBody2D
collide so I have all information about the two bodies at the moment of collision.
My goal is to make any body that touches the spring reach a certain height (from the spring), and move by certain speed horizontally, as you can see in the picture
So, the information about both bodies I have is: position, velocity, gravity scale, mass, weight.
What I want to achieve is constant line of movement of any object (that may have different properties I mentioned above) by applying a certain force to the colliding object.
I can stop the body before applying new force to it, that is, at the time of collision.
Rotation, friction, absorption and similar properties don't need to be counted on as the game I'm making is a simple one. With this I'm trying to make a predictable movement for the player to count on. I also plan to disable collision briefly at the time of collision so that the colliding object can touch the spring from any angle and the collision result would be the same.
EDIT: Here's some of my testing
Stones have random mass from 1 to 50, in this case 45.748413, 41.445225, 24.259401 and 37.189552 and all have same gravity scale (GS), that is: 2. The slime has GS of 5 and mass of 1.
I bothered to make a seamless gif, so you can only see the two jumps here. Because the spring has circular shape they fall apart after i think 10 bounces.
From this test I see that mass doesn't matter when I use @Sergio's method, so that's a step foreward. Thanks @Sergio!
func _on_body_entered(body):
if body is RigidBody2D:
body.set_linear_velocity(Vector2(0, -50 * body.gravity_scale))
Now, even though they don't reach the same height, they have same timing - from first touching the spring (yeah, i know, it doesn't look like a spring), to falling back. So that's also a step foreward, but I still don't have an idea how to get them all to get to the same height.