   Little help about sliding along wall
  Hello everyone.I have no problem with collision detection in 3d world and with 3d meshes as you can see in attached picture i could realize all 8 corners of my mesh and create bounding box with them.this is a little part of my character class:class Character{public Vector3 Direction { get; set; }public Vector3 OrthoVector { get; set; }public float Rotate { get; set; }   public void Update(GameTime GameTime)   {  if (Keyboard.GetState().IsKeyDown(Keys.Up)) if (CanMoveForward)Position -= 5 * Direction;  if (Keyboard.GetState().IsKeyDown(Keys.Down)) if (CanMoveBackward)Position += 5 * Direction;  if (Keyboard.GetState().IsKeyDown(Keys.Left))  { OrthoVector = Vector3.Cross(Vector3.Up, Direction); Direction += 0.05f * OrthoVector; Rotate = (float)Math.Atan2(Direction.X, Direction.Z); Direction.Normalize();  }  if (Keyboard.GetState().IsKeyDown(Keys.Right))  { OrthoVector = Vector3.Cross(Vector3.Up, Direction); Direction -= 0.05f * OrthoVector; Rotate = (float)Math.Atan2(Direction.X, Direction.Z); Direction.Normalize();  }   }}I can catch intersecting character with my mesh by this method: "Intersect(Character character)"Now My question:I want change character.direction to wall direction for sliding it along the wall.This is my idea:I created 6 plane with MeshCorners with this command:Plane[0] = new Plane(MeshCorners [0], MeshCorners [1], MeshCorners [2])Now i can get angle between my character.Direction and plane[0].Normal:protected override void Update(GameTime gameTime){float angle = 0;Vector3 TempDirection = Vector3.Zero;txt = angle.ToString();if (L.ABDAPN(Ch, out angle)) /*ABDAPN return angle between intersected planes normal and character.direction*/{Matrix m = Matrix.CreateFromAxisAngle(Vector3.Up, 3 * MathHelper.PiOver2 + angle);Ch.Direction = Vector3.TransformNormal(Ch.Direction, m);Ch.Rotate = (float)Math.Atan2(Ch.Direction.X, Ch.Direction.Z);}Ch.Update(gameTime);base.Update(gameTime);}But its not working Any new idea or improved way of my idea?Sorry about my bad English this is attached picture:http://www.imgplace.com/viewimg149/3301/40attachedboundingbox.pngThanks.   
  I've never done this, but IMHO you just need to take the theoretical movement vector of the character and decompose it into the normal component and tangential component in respect to the wall. The normal vector will just mean how strongly is the character pushing into the wall while the tangential vector is your desired new movement vector.To get the normal component you'll need the normal vector of the wall and use dot product (simply said). Then to get the tangential you'll just subtract the normal component from the original movement vector.   ;  Hi Tom KQT.Thanks for your reply.yes you right and i used these methods can u tell me where is wrong?this is my ABDAPN method:public bool ABDAPN(Character Character,out float Angle){Vector3 normal = Vector3.Zero;if (this.Intersect(Character, out normal)){Angle= (float)Math.Acos((double)Vector3.Dot(Character.Direction, normal));return true;}Angle = float.NaN;return false ;}and this is my Intersect method:public bool Intersect(Character character, out Vector3 Normal){Normal = Vector3.Zero;foreach (LevelEntity Part in this.Parts){if( Part.Intersect(character, out Normal))return true;}return false;}and this is my LevelEntity Intersect method:public bool Intersect(Character character,out Vector3 Normal){Normal = Vector3.Zero;if (this.BoundingBox.Intersects(character.BoundingBox)){Normal = GetNearstFaceNormal(character.Position);return true;}return false;}and GetNearstFaceNormal method is:public Vector3 GetNearstFaceNormal(Vector3 Position){int TempIndex=GetNearestFace(Position);if (TempIndex < 0) return Vector3.Zero;elsereturn this.Surfaces[TempIndex].Normal;}and GetNearestFace method is:public int GetNearestFace(Vector3 Position)   {List<float> Distances = new List<float>(0);foreach (Surface Face in this.Surfaces){Distances.Add(Face.AbsOfDistance(Position));}if (Distances.Min() == this.Surfaces[0].AbsOfDistance(Position)) return 0;if (Distances.Min() == this.Surfaces[1].AbsOfDistance(Position)) return 1;if (Distances.Min() == this.Surfaces[2].AbsOfDistance(Position)) return 2;if (Distances.Min() == this.Surfaces[3].AbsOfDistance(Position)) return 3;return -1;}but it still has problem.;  Moving to Math & Physics, you'll probably get more replies there.   ;Quote:Original post by Evil SteveMoving to Math & Physics, you'll probably get more replies there.Thanks.But maybe my problem is in plane.normal or etc depend on xna i think.[Edited by - Saeed Masoumi on June 8, 2010 2:51:06 PM]