(…)
procedure TLeft.Update(const SecondsPassed: single; var RemoveMe: TRemoveType);
begin
inherited Update(SecondsPassed, RemoveMe);
with Parent do
begin
TranslationXY := TranslationXY + Vector2(100 * SecondsPassed, 0);
end;
end;
procedure TLeft.Collision(const CollisionDetails: TPhysicsCollisionDetails);
begin
WritelnLog(‘Colision’);
end;
(…)
Hm, I don’t see in the code actually usage of TRigidBody.
Indeed it is deprecated – if you have it anywhere, you should change it to TCastleRigidBody (which is a bit different, but also better on all accounts).
If you want to detect when something collides, you’d use e.g. TCastleRigidBody.OnCollisionEnter event ( Castle Game Engine: CastleTransform: Class TCastleRigidBody ). The example examples/physics/physics_2d_collisions/code/gameviewmain.pas has some code to demonstrate this.
Hopefully this answer is helpful, if it’s not enough – please post a more complete source code, I’ll be able to help more precisely then
Hello Michalis, thanks for answer. But I’m confused. I saw the exampled that you point. In the example, all components are created in editor, then in the code you can used.
But In my code I created a transform castle. Then I load it and I try to get collision.
I post a zip file with all code,may be can explain better than me (there is some garbage, but excuse me because it is a test code).
Everything that you can design in editor, you also create from code – just using the same class names, property names. examples/physics/physics_2d_collisions/ uses TCastleRigidBody class for behaviors
Testing your example, I get a different warning at a similar line with latest CGE:
gameviewmain.pas(175,10) Warning: Symbol "RigidBody" is deprecated: "use AddBehavior (to set)/FindBehavior (to get)"
Body1 := Box1.FindBehavior(TCastleRigidBody) as TCastleRigidBody;
Body1.OnCollisionEnter := @aLeft.Collision;
and declare Body1: TCastleRigidBody local variable in the routine.
I know – new version is longer. But it is more consistent with other behaviors, we decided for now to get rid of “RigidBody” shortcut that is also connected to deprecated “TRigidBody”. Maybe it will come back one day, I can see how it would be just convenient in this case.