Sign in to follow this  
Meshboy

Im soooOOOOO Close, help finish this!

Recommended Posts

I am getting too close up against my walls in my FPS. This causes the player to slide through corners that are smaller than 90degrees. If i remove this check: if (Vector3.Dot(p.NormalVector(), move_v) < 0) then it works but it gives a not nice effect by pushing the player out against a wall when eaven not looking at it. objCamera.mPos = players position move_v = direction and speed vector. in the end, the Camera moves by the move_v vector. //Radius = 1.5f; //This is the walls, two X,Y,Z vectors that defines a line. (its not really 3D) foreach (types.cPlane p in planes) { if (Vector3.Length(p.ClosestPointOnPlane(objCamera.mPos) - objCamera.mPos) < Radius) { //Now, this is the funny part, if i remove the codeline under and not check the //players view against the wall everything works but gives a rather "fast" slide-speed in corners, too fast and then its not smooth again, but if i add this i can walk through narrow concave corners ,not edges. (they work fine) ---> if (Vector3.Dot(p.NormalVector(), move_v) < 0) { vMove.Add(p.NormalVector() * (Radius - Vector3.Length(p.ClosestPointOnPlane(objCamera.mPos) - objCamera.mPos))); //Feels like i am missing something here, why is the player still moving slightly closer against the wall when holding in the Forward Key? } //Here i add all the Wall-Normal-vector so the player is "pushed" out from the wall. foreach (Vector3 v in vMove) { move_v += v; } //This is my speed and direction vectors vforward = (objCamera.mView - objCamera.mPos) * forward; vbackward = -(objCamera.mView - objCamera.mPos) * backward; vleft = classes.utility.GetNormalVector(objCamera.mView - objCamera.mPos) * left * 3; vright = -classes.utility.GetNormalVector(objCamera.mView - objCamera.mPos) * right * 3; //make a completely new move vector by adding all directions. move_v = (vforward * forward) + (vbackward * backward) + (vleft * left) + (vright * right); //When hitting the W the forward floatnr starts to increase and the move-vector getts longer (more speed) and so on. //PS if anyone want to check the code, i will gladly send it. C# Managed Direct3D. [Edited by - Meshboy on August 12, 2008 12:49:05 PM]

Share this post


Link to post
Share on other sites
Solved it!
Now everything works with all kinds of edges and corners!

private void CollideWithWorld() {
float Radius = 1.0f;
//Collision detection start.
vPushVectors.Clear();
objText.Draw2DText("length move_v" + Convert.ToString(move_v.Length()), 0, 100, Color.Red);
//add all the normal vectors of the planes that are too close to player.
foreach (types.cPlane p in planes) {
//Check the lenght from player to planes.
float length = Vector3.Length(p.ClosestPointOnPlane(objCamera.mPos) - objCamera.mPos);
if (length < Radius) {
//Add to pushout vector collection.
vPushVectors.Add(p.NormalVector() * (Radius - length));
}
}
//Oookay, check the convex or concave angles.
//If player hit 2 wall then we are in a corner or edge.
if (vPushVectors.Count == 2) {
objText.Draw2DText("DOT" + Convert.ToString(Vector3.Dot(vPushVectors[0], move_v)), 300, 700, Color.Red);
objText.Draw2DText("SPECIAL" + Convert.ToString(Vector3.Dot(vPushVectors[0], vPushVectors[1])), 300, 740, Color.Red);
//If Vector3.Dot(vMove[0], vMove[1])>= 0 then we are in a corner that is 90 degrees or MORE,
//so here we can take only the wall player is facing.
if (Vector3.Dot(vPushVectors[0], vPushVectors[1]) >= 0) {
//Wall nr 1
//If player is facing wall, then add correction vector.
if (Vector3.Dot(Vector3.Normalize(vPushVectors[0]), move_v) < 0) {
move_v += vPushVectors[0];
}
//Wall nr 2
//If player is facing wall, then add correction vector.
if (Vector3.Dot(Vector3.Normalize(vPushVectors[1]), move_v) < 0) {
move_v += vPushVectors[1];
}
}
// If we ARE in a sharp Corner (less than 90 degrees, skip player facing check and just push him out from
// normals from both walls.
else {
move_v += vPushVectors[0];
move_v += vPushVectors[1];
}
}
// If player only sliding on one wall, check that one for facing-against wall and push him out,
// normal standard.
if (vPushVectors.Count == 1) {
if (Vector3.Dot(Vector3.Normalize(vPushVectors[0]), move_v) < 0) {
move_v += vPushVectors[0];
}
}
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this