# Using Motionpaths for game logic?

I’m new 2 jme3 and want to make a rts game with physics integration. so i want my geometries 2 be able 2 walk along a list of waypoints but also interact with other physic objects. EXAMPLE: my geomeztry is on his way but then a physical force pushes it away from its path. is this possible and can i use motionpath for this issue or do i have to implement this functionallity by myself via controls?

what you could do is use a MotionPath and a MotionEvent (the control) and disable the MotionEvent upon collision with another object.

1 Like
@nehon said:
what you could do is use a MotionPath and a MotionEvent (the control) and disable the MotionEvent upon collision with another object.

so after collision i activate the motionevent (with a new motionpath) when the geometry stands still. or how could i handle this?
can a geometry leave its motionpath? is there an opinion to change the movementtype of motionevents from linear velocity to apllyForce? or can i even write my own MotionEvent? or thinkin im completly wrong? are there simmilar solutions that uses kinda motionpaths etc. for moving spatials in its gam logic?
meny questions... mh sorry for my bad english

A motionEvent is a control that make the spatial follow a motionPath. If you disable this control you can go and setLocalTranslation or whatever on the spatial.

You gonna need to add a RigidBodyControl on the spatial too that you can set to Kinematic (interact with other physical objects but is not affected by physics). This way during it’s movement along the path it can “push” other objects.

Then when you detect a collision with an impact over a certain threshold, you deactivate the kinematic mode of the rigid control, and you deactivate the motionEvent.

The spatial should be pushed away from the path.

Then you can go an build another path to make it resume its way from its new location, and reactivate the MotionEvent and so on…

@nehon said:
Then you can go an build another path to make it resume its way from its new location, and reactivate the MotionEvent and so on....

how can i recognize, that the physics collision impact is over for going back to kinematic mode? i use a control which implements PhysicsCollisionListener.

Edit: and how can i handle collision detection between 2 kinematic objects? currently my kinematic objects can overlap each other

if your spatial position doesn’t change over a certain threshold (I mean it stopped to move) that means it can resume its path.

for the second question I’m afraid i can’t answer. @normen is there a way to detect collision between 2 kinematic rigid bodies?

They should report collision as normal. Otherwise for not having to care about collision and how to stop you can use the “hack” of continuously setting the directional and rotation velocity of the object. You drop the physics computations this way which makes them unnecessary overhead though.

@nehon said:
if your spatial position doesn't change over a certain threshold (I mean it stopped to move) that means it can resume its path.

does this mean i have to check the moving distance of the physicsLocation over two or more physic-tiks and when this distance gets to zero i can change the mode? or what do you mean with threshold?

@normen said:
They should report collision as normal. Otherwise for not having to care about collision and how to stop you can use the "hack" of continuously setting the directional and rotation velocity of the object. You drop the physics computations this way which makes them unnecessary overhead though.

sry, but i dont get it

If you continuously set the velocity of an object it will stop when e.g. bouncing into a wall. But at the same time it doesn’t react to the gravity etc. anymore as you “overwrite” the values that the physics calculations evaluated. Kinematic objects do report collisions but as you move them by setting a location they cannot possibly avoid ending up in a wall if you decide to put them there.