Details about apply_impulse's position

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ouyang

● void apply_impulse(position: Vector3, impulse: Vector3)

Applies a positioned impulse to the body. An impulse is time
independent! Applying an impulse every frame would result in a
framerate-dependent force. For this reason it should only be used when
simulating one-time impacts. The position uses the rotation of the
global coordinate system, but is centered at the object’s origin.

I cannot quite understand what that “The position uses the rotation of the global coordinate system, but is centered at the object’s origin.” means, is there anyone can give an example? thanks.

I think this means that the rotation is global, i.e. not relative to the rotation of the object, but the position is not global, i.e. it is relative to the object’s position.

SteveSmith | 2023-01-17 10:38

umm, thanks but i’m still not quite understand that yet.

I think it would be great if godot official doc gives some example of these Math related things :wink:

Really take time to understand that while no docs or tutorial for that implementation…

ouyang | 2023-01-18 01:26

To put it another way: every node has its own “local” rotation and position, but if it’s a child of another node(s), it’s overall (“global”) rotation and position is the total of all the local rotations and positions of it’s parent. For example, if a node has a “local” rotation of 15 degrees, and one of its child nodes has a local rotation of 30 degrees, then that child will actually be rotated by 45 degrees (i.e. its global rotation).

The same with position, e.g. if a parent node has a local position of 1, 1, 1 and a child has a local position of 2, 3, 4, that means its global position is 5, 6, 7.

Going back to your original question, the position in apply_impulse() “centered at the object’s origin” means its relative to the position of the child, so 0,0,0 would be the actual centre of that child.

Hope that helps…?

SteveSmith | 2023-01-18 07:18

Thanks a lot for your description. So, for example,
a ball in the world, take P1 as a local position in the ball’s orientation system,
if I wanna give the ball an impulse at the P1 location, I need to change the P1 to P2 which is the position described by the doc, rather than using P1 directly, right?

If so, is the bellowing transformation right?

P2 = ball.to_global(P1) - ball.global_translation

ouyang | 2023-01-18 12:30

I don’t think so. Since the function expects a position relative to the object (i.e. a local position) and P1 is a local position, you can just use P1.

In fact, I think your code there is going to return P2 as exactly the same as P1, since you’re converting it to_global, and then subtracting it’s global position to get back where you started.

SteveSmith | 2023-01-18 14:27