If EntityModel is the EntityModel from the BasicSetupDemo, then in the Draw method there is this line:
Code: Select all
Matrix worldMatrix = Transform * entity.WorldTransform;
In what way does it fail?But it doesn't work.
Code: Select all
Matrix worldMatrix = Transform * entity.WorldTransform;
In what way does it fail?But it doesn't work.
Code: Select all
ray.Position = cci.CharacterController.Body.Position;
ray.Direction = Vector3.Normalize(cci.Camera.WorldMatrix.Forward);
for (int i = 0; i < space.Entities.Count; i++)
{
if ((string)space.Entities[i].Tag == "pickupable")
{
if (ray.Intersects(space.Entities[i].CollisionInformation.BoundingBox) <= 50)
if (((Game1)Game).MouseInput.LeftButton == ButtonState.Pressed)
{
Vector3 pos = cci.CharacterController.Body.Position;
space.Entities[i].LinearVelocity = cci.Camera.WorldMatrix.Forward * 50;
space.Entities[i].AngularVelocity = Vector3.Zero;
space.Entities[i].Position = pos + cci.Camera.WorldMatrix.Forward * 20.0f;
// breaking out of the loop
i = space.Entities.Count;
}
}
}
I'd guess this is a byproduct of the particular way the velocity is being controlled.When I'm holding an entity in front of me, and rotate the camera with a mouse, the entity follows correctly, but its movement is a little "buggy" and not smooth at all.
It's weird because when I "move" with keyboard keys, the entity follows very nicely and smoothly.
Code: Select all
if (space.RayCast(ray, 50, out rcr))
Code: Select all
Vector3 goalpos = cci.Camera.Position + cci.Camera.WorldMatrix.Forward * 25.0f;
space.Entities[picking].LinearVelocity = (goalpos - space.Entities[picking].Position) * 15;
How can I do that?It might be good to set the collision rule of the box such that it cannot collide while held to avoid this
The RayCastResult does contain which object it hit in the HitObject field. It is a BroadPhaseEntry. Each entity has a entity.CollisionInformation which returns an EntityCollidable, which inherits from BroadPhaseEntry. That EntityCollidable is the entity's proxy in the collision detection pipeline that the ray cast sees. The associated Entity can be grabbed from it; read the first section of my previous post for more information.I attempted to use space.RayCast, but the result that it returns(RayCastResult), doesn't store the information about which space entity it is.
One option would be to set the entity.CollisionInformation.CollisionRules.Personal = CollisionRule.NoBroadPhase. Keep in mind this still lets you push things through walls (in fact, it becomes trivially easy because it doesn't collide with anything).How can I do that?
I'd stick to one of two main options:What I'm thinking, is that if the goal position is intersecting with any geometry in the space (except object itself), then don't reset it this update. That way, the object will keep moving towards the previous valid goal. Do you have any hints about this?
Code: Select all
public void addDynamic(string modelName, float mass, Vector3 position) {
Model temp = ((Game1)Game).Content.Load<Model>("Models/" + modelName);
Vector3[] vertices;
int[] indices;
TriangleMesh.GetVerticesAndIndicesFromModel(temp, out vertices, out indices);
ConvexHull ch = new ConvexHull(vertices, mass);
EntityModel entMod = new EntityModel(ch, temp, Matrix.CreateTranslation(-ch.Position), ((Game1)Game));
((Game1)Game).Components.Add(entMod);
ch.Position = position;
ch.Tag = modelName;
space.Add(ch);
}
Code: Select all
ch.WorldTransform *= Matrix.CreateScale(2);
Code: Select all
ConvexHullShape chs = new ConvexHullShape(vertices);
TransformableShape ts = new TransformableShape(chs, Matrix3X3.CreateScale(scale.X));
Most shapes have settable properties, like a box's Width, Length, and Height. ConvexHullShapes are not easily transformed since they just have a local vertex list. Putting a ConvexHullShape into a TransformableShape and using that TransformableShape to construct an entity is the easiest approach for convex hulls. Check out the EntityConstructionDemo in the BEPUphysicsDemos for an example of how to do this, but read the rest of the post before going down that road.how can I alter the scale of dynamic objects?
An entity's world transform can only contain a rigid transform. This means it contains a position and orientation. Attempting to assign a transformation which contains other components, such as scale, will be decomposed into position and orientation. The 'extra' components could cause the position and orientation to be incorrect.I also tried to do this:
ch.WorldTransform *= Matrix.CreateScale(2);
, but it doesn't seem to do anything.
The following assumes that this is truly related to objects which are too small. If you'd like me to verify that the problem is related, recreate a tiny isolated portion of the simulation including one of the too-small objects that has the problem in a BEPUphysicsDemo. I'll copy the code and take a look to make sure the problem is what it appears to be. (Attempting to fix a problem which isn't the real problem is, historically, ineffectiveThe reason I'm doing this, is that collision detection against small items (like a key or a match box) is really bad, and it just goes through the floor sometimes. So, I increased the size of actual models, and I want to scale them down in the actual game, perhaps that will make it better.
Oh, ok. That sounds awfully correct - I don't know why I hesitated.Increasing the model size and then re-shrinking it after the fact will not help if it is reduced all the way back down to a size which is too tiny; the engine only cares about the final state of the simulation shape.
Code: Select all
ConfigurationHelper.ApplyScale(28);