AplyImpulse in 2D

Hello, I making a small test to understand applyimpulse.
I created a new blank project. I add a Viewport for 2D.
I added Behaviours to the plane1. I

imagen
imagen
imagen

In my code I wrote:

published
{ Components designed using CGE editor.
These fields will be automatically initialized at Start. }
LabelFps: TCastleLabel;
Plane1: TCastlePlane;
public
(…)
unction TViewMain.Press(const Event: TInputPressRelease): boolean;
var
body: TCastleRigidBody;
begin
Result := inherited;
if Result then Exit; // allow the ancestor to handle keys

if Event.IsKey(keySpace) then
begin
body := Plane1.FindBehavior(TCastleRigidBody) as TCastleRigidBody;
Body.ApplyImpulse(Vector3(10000,0,0),Plane1.WorldTranslation);
Exit(true);
end;
end;

But When I run the code, and I press space bar, the plane doesn’t do any thing, only continues moving down by the gravity

What I doing wrong?
Thanks
/BlueIcaro

Hm, on the first glance I don’t see what is wrong. Your setup and your code look good, this is exactly how I would apply an impulse to an object.

Can you share the complete project with the problem? I will be happy to investigate :slight_smile:

P.S. Instead of

body := Plane1.FindBehavior(TCastleRigidBody) as TCastleRigidBody;

you can also write

body := Plane1.RigidBody;

( it is exactly equivalent, always, guaranteed. That is, Xxx.RigidBody is just a shortcut for Xxx.FindBehavior(TCastleRigidBody) as TCastleRigidBody , implemented with a tiny optimization. )

Hello, don’t worry. I fixed it.

Body.ApplyImpulse(Vector3(1, 1, 0) * 10000, Box1.WorldTranslation);

The problem was that I don’t give enough force. I put 10000 as you can see and now works
Thanks
/BlueIcaro

1 Like