Page 1 of 1

Adding levels and a player (first person shooter)

Posted: Sun Mar 27, 2011 8:19 pm
by protomor
Ok so I think I figured out the basics:

Create space object.
Add gravity
Add physics related things to space object
update physics every update
profit?


I think I have my .x level model correct:
Vector3[] staticTriangleVertices;
int[] staticTriangleIndices;

TriangleMesh.GetVerticesAndIndicesFromModel(m, out staticTriangleVertices, out staticTriangleIndices);
staticMesh = new StaticMesh(staticTriangleVertices, staticTriangleIndices, new AffineTransform(Matrix3X3.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), new Vector3(0, -10, 0)));
staticMesh.Sidedness = TriangleSidedness.Counterclockwise;
and then add the staticmesh to the space object.

I create my player object given the camera position then give it roughly the dimensions I think the player should be using a Box object.

I haven't been able to link the camera to the player physics object yet but I've been tracking the player's position. It's definitely doing some collision since it will only fall to 40y before it stops. If I take the level physics object out, It'll just keep going down. But I can't seem to stop the player when it comes in contact with a wall.

Maybe I'm not hooking up the player position with the physics position properly? What is the best way to do this?

Also, when I make a box, you feed it: vec3, float, float, float, float. The last float is for "m". What is m?

Re: Adding levels and a player (first person shooter)

Posted: Sun Mar 27, 2011 8:59 pm
by Norbo
But I can't seem to stop the player when it comes in contact with a wall.

Maybe I'm not hooking up the player position with the physics position properly? What is the best way to do this?
What might be happening is that the entity is being controlled using Position setting rather than velocity. Setting the Position/Orientation of an entity teleports it. When it reaches a wall, the character will gladly teleport through it since the collision response system has no velocities to work with. Instead of using the Position/Orientation to move objects around, set their velocities (LinearVelocity, AngularVelocity, or equivalently changing LinearMomentum/AngularMomentum and using ApplyImpulse).
Also, when I make a box, you feed it: vec3, float, float, float, float. The last float is for "m". What is m?
Mass (changed that 'm' to 'mass' in the upcoming v0.15.2 :)).

Re: Adding levels and a player (first person shooter)

Posted: Mon Mar 28, 2011 12:55 am
by protomor
Hmm. What's the best way to implement that with an already working camera with controls? I guess transfer all the movement controls to the physics object and control the view that way? What about the box toppling over? IE the player would "fall over".

Re: Adding levels and a player (first person shooter)

Posted: Mon Mar 28, 2011 1:01 am
by Norbo
I guess transfer all the movement controls to the physics object and control the view that way?
Correct.
What about the box toppling over? IE the player would "fall over".
Setting the LocalInverseInertiaTensor to a zeroed-out matrix will prevent it from undergoing any angular motion (zeroed-out inverse inertia is like infinite inertia).

Re: Adding levels and a player (first person shooter)

Posted: Mon Mar 28, 2011 3:06 am
by protomor
I just took the simplecharactercontroller class from the sample and used that. But for some reason, all collisions are offset. IE I made a pole but I pass right through it. I'll "hit" the pole just a little bit behind it and to the left. I didn't set any offsets. Why is that happening?

Re: Adding levels and a player (first person shooter)

Posted: Mon Mar 28, 2011 3:54 am
by Norbo
It sounds like the thing used to visually determine the position of the character (camera? model?) doesn't actually match the shape. You could try adding some extra simple visualization, like drawing a line where the character's body is, or using the BEPUphysicsDrawer from the BEPUphysicsDemos project, to see if things match your expectations.

Re: Adding levels and a player (first person shooter)

Posted: Mon Mar 28, 2011 4:47 pm
by protomor
Everything was rotated 180 on the Y axis... Odd. I wonder why.