Static Objects
Static Objects
Is there a way, to reposition a static object? If I made a static triangle group out of a city building, is it possible to move the object, and the physics calculations to a different spot?
If so, any examples or code you could give me?
Thanks,
-Piers
If so, any examples or code you could give me?
Thanks,
-Piers
Re: Static Objects
A StaticTriangleGroup's world matrix can be changed to rotate, scale, and translate the mesh.
For example, to move the mesh down 10 meters, you could use this code:
In the demos, there is a line in the Playground simulation that rotates the mesh 180 degrees and then moves it down as well:
For example, to move the mesh down 10 meters, you could use this code:
Code: Select all
group.worldMatrix *= Matrix.CreateTranslation(0, -10, 0);
Code: Select all
group.worldMatrix = Matrix.CreateFromYawPitchRoll((float)Math.PI, 0, 0) * Matrix.CreateTranslation(0, -10, 0);
Re: Static Objects
Hmm... any idea why it wouldn't work in the update, and/or draw function?
Re: Static Objects
Not that I can think of; is it possible that the collision mesh is moving but not the associated graphics?
Re: Static Objects
Just thought of one reason. If it's being called every frame, the worldMatrix change will clear out the currently active objects. If they aren't remade in time, no collision occurs. I'm currently trying to find a way to allow continued modifications.
Re: Static Objects
The solution is to call group.updateAtEndOfUpdate(space.simulationSettings.timeStep, space.simulationSettings.timeScale, 0); manually after adjusting the group's world matrix. Doing so forces the recreation of any missing triangles. This isn't an ideal way for it to work, and I would like to make it quicker and more obvious in the next version.
Re: Static Objects
Thank you very much. : ) I'll be sure to try that as soon as I get my source back.
Edit:
Actually, I now have a sort of new problem. It appears that my object, no matter the radius I put the sphere at, never touches the ground. It physically moves across the ground, but it is always above it.
Edit:
Actually, I now have a sort of new problem. It appears that my object, no matter the radius I put the sphere at, never touches the ground. It physically moves across the ground, but it is always above it.
Re: Static Objects
If the sphere is successfully generating contacts, then what you are observing is the margin of the sphere. If your graphics are designed to show the sphere with the sphere's radius rather than the sphere's radius added to the margin, there will be a gap.
In the demos, I deal with this by expanding all graphical representations by the margin (minus the allowed penetration). Subtracting the allowed penetration can leave gaps, though objects won't be graphically penetrating while at rest. If you'd rather not have any visible gap in favor of a little penetration, then just expanding simply by the margin would be fine. Modifying the radius of the sphere until it matches the preexisting graphics would work too.
Now if is actually bobbing along as if it were under antigravitational effects or something, then I'm not quite sure.
In the demos, I deal with this by expanding all graphical representations by the margin (minus the allowed penetration). Subtracting the allowed penetration can leave gaps, though objects won't be graphically penetrating while at rest. If you'd rather not have any visible gap in favor of a little penetration, then just expanding simply by the margin would be fine. Modifying the radius of the sphere until it matches the preexisting graphics would work too.
Now if is actually bobbing along as if it were under antigravitational effects or something, then I'm not quite sure.
Re: Static Objects
Right... another problem. I made a character, who has a cylinder to affect it's gravity/collisions. Main problem is, the moveTo command seems to be stopping this object from interacting with any other object. I can run around on my terrain.. but running into a sphere just makes me move over it.
Help please?
Help please?
Re: Static Objects
moveTo teleports the entity, so you will phase through any objects you do not manually detect collisions against (though any moveable entity will try get away from you, provided that your cylinder is handled by the space). In the demos' character controller, this is resolved by using a dynamic rigid body which detects collisions with the environment and moves due to velocities rather than teleportation. Another common method is to use swept collision tests to see how far an entity can move, or to detect penetration with discrete tests and resolve it after the fact.
Personally, I find working on the impulse/velocity level more intuitive, hence the usage of a physically simulated rigid body.
Personally, I find working on the impulse/velocity level more intuitive, hence the usage of a physically simulated rigid body.
Re: Static Objects
How would I go about velocities and shit in Bepu? If moveTo teleports, then what actually moves the object?
Re: Static Objects
You can change momentums and velocities using the linearMomentum/angularMomentum/linearVelocity/angularVelocity fields. There's also applyImpulse. You can see in the demos' character controller how I handle a character's movement using velocities.
Here's a simple way to convert a position based system to a velocity based system. If you have a goal displacement vector (current position to goal position), you can divide it by the timestep to get the velocity (in units per second) that the entity would need to move that direction. Setting the entity's velocity to that value would cause it to move in the same way, but it would be changed by collisions and therefore wouldn't phase through stuff.
In the demos, I don't use goal positions or anything like that though. I simply create a movement direction based on the keyboard/mouse input and accelerate in that direction by changing the body's velocity and let the collision detection and response systems figure out the limitations.
Here's a simple way to convert a position based system to a velocity based system. If you have a goal displacement vector (current position to goal position), you can divide it by the timestep to get the velocity (in units per second) that the entity would need to move that direction. Setting the entity's velocity to that value would cause it to move in the same way, but it would be changed by collisions and therefore wouldn't phase through stuff.
In the demos, I don't use goal positions or anything like that though. I simply create a movement direction based on the keyboard/mouse input and accelerate in that direction by changing the body's velocity and let the collision detection and response systems figure out the limitations.
Re: Static Objects
Hello,
i also had have the problems with a moveTo() under JigLibX. I need some hours to check that such methods aren't useable if u like a physical response!somehow also logically...
So i saw that u also have such a method in your character controller!It should be usefull when u make it private!So a person who is new to the topic(like i was then) is using first such methods cuz they don't know that its going on with forces, impuleses etc..
Just my 2 cents
i also had have the problems with a moveTo() under JigLibX. I need some hours to check that such methods aren't useable if u like a physical response!somehow also logically...
So i saw that u also have such a method in your character controller!It should be usefull when u make it private!So a person who is new to the topic(like i was then) is using first such methods cuz they don't know that its going on with forces, impuleses etc..
Just my 2 cents