AI and physics

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Bonus
Posts: 9
Joined: Mon Mar 21, 2011 2:35 pm

AI and physics

Post by Bonus »

Hi, Norbo

I'm currently programming a space shooter.
You can watch it here http://www.youtube.com/watch?v=Gjbu3f6Zngg

I have a few questions:
1. Can I get rid of the inertia of motion and rotation? It is necessary for precise positioning of the AI. All I need is a couple of methods Move(Vector3 offset) and Rotate(Quaternion offset). Is it possible?
2. How to disable the ships to push each other in some cases? As well as players in the Quake ​​can't push each other.

P.S. Sorry for my bad english
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: AI and physics

Post by Norbo »

I'm currently programming a space shooter.
You can watch it here
Looks great!
1. Can I get rid of the inertia of motion and rotation? It is necessary for precise positioning of the AI. All I need is a couple of methods Move(Vector3 offset) and Rotate(Quaternion offset). Is it possible?
The Position and Orientation fields can be set.

I would be wary of using them to perform regular movement though. They do not work using velocities, but rather teleportation. Continuous collision detection and collision response won't work as expected since the velocities won't match the motion. Going down this route almost always causes some issue later where physics are trying to interact with nonphysically controlled objects.

If it's okay for the objects be a little behind their goal position and orientation, you could consider using SingleEntity(Linear/Angular)Motor, or the helper classes EntityMover and EntityRotator. These can be used to 'target' a goal state to which the controlled entity will work towards with configurable force and speed.

Basically, the recommended way is always to use velocities and forces to control the motion of dynamic entities. The closer the control scheme gets to that, the less special case annoyances will sneak in.
2. How to disable the ships to push each other in some cases? As well as players in the Quake ​​can't push each other.
The collision rules system can be used to control how entities interact in some ways. It's primarily useful for short circuiting out of the collision pipeline at the desired location, so the result would be objects simply not colliding with each other. More information can be found here: http://bepuphysics.codeplex.com/wikipag ... umentation

If you want an object to act as if it has infinite mass, you can make it kinematic (construct it without giving it a mass, or later call entity.BecomeKinematic). They have effectively infinite mass and inertia.

If you require more fine-tuned control over when objects are treated as if they have infinite mass, you're looking at controlling collision response manually. In this situation, you could make all ships as kinematic, still control their motion through velocities preferably, and then when collisions occur, apply your own "collision forces." A pair of kinematic objects does not undergo collision response since they both have infinite mass. However, you could intervene and change their velocities based on bounding volume overlap or contact points.
Bonus
Posts: 9
Joined: Mon Mar 21, 2011 2:35 pm

Re: AI and physics

Post by Bonus »

Looks great!
Thanks!
If it's okay for the objects be a little behind their goal position and orientation, you could consider using SingleEntity(Linear/Angular)Motor, or the helper classes EntityMover and EntityRotator. These can be used to 'target' a goal state to which the controlled entity will work towards with configurable force and speed.
EntityMover and EntityRotator are very useful classes, and I use them now.
But how can I minimize the inertial lag, especially during the rotation? Previously, I used a different physics engine. At each iteration, I clear the linear and angular velocity, and then applied a force to move the body. Value of the force must have been very large, but this hack worked. Can I do something similar in BEPU?
Very difficult to set tasks to AI when it can't precisely position the object that is managed.
The collision rules system can be used to control how entities interact in some ways. It's primarily useful for short circuiting out of the collision pipeline at the desired location, so the result would be objects simply not colliding with each other. More information can be found here: http://bepuphysics.codeplex.com/wikipag ... umentation

If you want an object to act as if it has infinite mass, you can make it kinematic (construct it without giving it a mass, or later call entity.BecomeKinematic). They have effectively infinite mass and inertia.

If you require more fine-tuned control over when objects are treated as if they have infinite mass, you're looking at controlling collision response manually. In this situation, you could make all ships as kinematic, still control their motion through velocities preferably, and then when collisions occur, apply your own "collision forces." A pair of kinematic objects does not undergo collision response since they both have infinite mass. However, you could intervene and change their velocities based on bounding volume overlap or contact points.
I need a behavior similar to PathFollowingDemo where flying figure can't deviate from the path. But only for the 'AI' vs 'UserShip' and 'UserShip' vs 'UserShip' in multiplayer.
Can I configure this behavior through the collision rules?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: AI and physics

Post by Norbo »

But how can I minimize the inertial lag, especially during the rotation? Previously, I used a different physics engine. At each iteration, I clear the linear and angular velocity, and then applied a force to move the body. Value of the force must have been very large, but this hack worked. Can I do something similar in BEPU?
You could increase the strength of the motor (in its Settings.Servo.SpringSettings property), but there will always be a tiny amount of delay when managing dynamic entities.

If the entity controlled is kinematic, the EntityMover/Rotator will apply velocities that will get the entity to its goal in a single frame. I personally prefer to keep things as physical as possible, though.
I need a behavior similar to PathFollowingDemo where flying figure can't deviate from the path. But only for the 'AI' vs 'UserShip' and 'UserShip' vs 'UserShip' in multiplayer.
Can I configure this behavior through the collision rules?
If both ships involved in a collision cannot deviate from their own paths, then they would fly through each other as if the collision didn't exist. That can indeed be done using CollisionRules.

If you don't want them to go through each other, then you'll have to decide exactly how they interact. Once that's figured out, the regular collision response between a pair of objects can be disabled using collision rules, and custom logic can be used instead when a collision occurs. For example, you could prioritize one ship over the other, and cause the smaller one to bounce off by applying an arbitrary force while letting the bigger one keep moving uninterrupted.

If you end up wanting to make everything kinematic, it will work similarly. Set up the collision rules, and define the custom logic. However, since kinematic entities do not respond to normal collisions (they have infinite mass), you'd have to control ALL of their interactions.
Post Reply