RayCasting and Player detection
Posted: Sat May 18, 2013 11:09 pm
Hello teacher Norbo , I have used rayCast methode as shown in the code below to detect player "Me" so that enemy take behaviour (attack , jump ,run ,crouch ......etc)
Now it works very very very bad as I must be in front , right , left , forward enemy so that he will attack !! so that any one play game must wate and be exactly in one of the previous positions so that ray detect him and enemy start to chase him !!!!
Norbo how to improve that and make it detect player while it's in the range of 100 meter and so on

Code: Select all
if (enemyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 200)
{
RunController(dwarfAnimator, walk);
enemyChrachterController.Body.ApplyImpulse(enemyChrachterController.Body.OrientationMatrix.Forward,
Vector3.Normalize(enemyRay.Direction) * 100.0f);
//enemyChrachterController.HorizontalMotionConstraint.MovementDirection =
// Vector2.Normalize(new Vector2(dwarfPosition.X, dwarfPosition.Z)) * enemyChrachterController.Body.Mass;
}
enemyRay.Position = enemyChrachterController.Body.Position;
enemyRay.Direction = Vector3.Normalize(enemyChrachterController.Body.OrientationMatrix.Right);
if (enemyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 200)
{
RunController(dwarfAnimator, walk);
enemyChrachterController.Body.ApplyImpulse(enemyChrachterController.Body.WorldTransform.Forward,
Vector3.Normalize(enemyRay.Direction) * 150.0f);
}
enemyRay.Position = enemyChrachterController.Body.Position;
enemyRay.Direction = Vector3.Normalize(enemyChrachterController.Body.WorldTransform.Forward);
if (enemyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 200)
{
RunController(dwarfAnimator, walk);
enemyChrachterController.Body.ApplyImpulse(enemyChrachterController.Body.WorldTransform.Forward,
Vector3.Normalize(enemyRay.Direction) * 150.0f);
}
enemyRay.Position = enemyChrachterController.Body.Position;
enemyRay.Direction = Vector3.Normalize(enemyChrachterController.Body.WorldTransform.Backward);
if (enemyRay.Intersects(cci.CharacterController.Body.CollisionInformation.BoundingBox) <= 200)
{
RunController(dwarfAnimator, walk);
enemyChrachterController.Body.ApplyImpulse(enemyChrachterController.Body.WorldTransform.Forward,
Vector3.Normalize(enemyRay.Direction) * 150.0f);
}
Norbo how to improve that and make it detect player while it's in the range of 100 meter and so on
