Thomas Barthélémy wrote:
Still got some problems with that,
I first tried to keep the PhysicsActor sent by the World.AddActor methods,
then casted the PhysicsActor.Actor to a IDynamicActor but the Actor seems to be null.
It's the good way but there are some "hidden" behaviors that could make the problem complicated. PhysicsActor is the class that bind the physics actor to a SceneNode. Basically, it's an INodeController that gets the actor position in the physics world to update the node position in the graphical world.
As we want the physics actor to be initialized with the node position, we create it on the node first update. The algorithm is :
- node is created with a position
- PhysicsActor is created and attached to the node
- First Update : underlying actor is created in the node position
- Other updates : node position is overridden by the actor position
So to apply force on the underlying actor, you must wait the actor creation. There is a bool properties "IsActorCreated" that keeps the creation status, so if you keep a reference to the PhysicsActor, you should be able to add force as soon as this property is true.
An other approach (which could be "cleaner"), is to subscribe to the filtered event ActorAddedFiltered on the PhysicsWorld that will be raised when the actor is created.
In the release version, there will be a third way with an "ActorCreated" event directly on the PhysicsActor class (it's hidden in the beta).
Regards