A.I & Path Following In Bepuphysics
Posted: Thu Feb 28, 2013 3:25 pm
Hi, i have two questions.
First one, i am trying to get an a.i Vehicle entity yo drive around a track itself, i have my raycast all set up for navigating through the track and all. What i did was that once it detects through a raycast that its far away from the wall of the track it should rotate back to be in line with the wall. No matter the calculations i do i can't seem to get it to rotate right.
Here is my code snippet.
The accelerate method there is simply this
Secondly, if i change method to using pathtfinding like the example I found in the demo, it moves, along the line perfectly, but it never rotates to face the forward direction of the curve, so its like the car moves on its side, then back to its front and so forth.
Where could i be wrong?
First one, i am trying to get an a.i Vehicle entity yo drive around a track itself, i have my raycast all set up for navigating through the track and all. What i did was that once it detects through a raycast that its far away from the wall of the track it should rotate back to be in line with the wall. No matter the calculations i do i can't seem to get it to rotate right.
Here is my code snippet.
Code: Select all
this.Accelerate();
if (rdistance > 3)
{
steered = true;
Vector3 right = new Vector3(3, 0, 0);
Vector3 difference = position - right;
Vector3 newForwardUnit = Vector3.Normalize(Vehicle.Body.Position - right);
Vector3 rotAxis = Vector3.Cross(Vehicle.Body.OrientationMatrix.Forward, newForwardUnit);
float rotAngle = (float)Math.Acos(Vector3.Dot(Vehicle.Body.OrientationMatrix.Forward, newForwardUnit));
angle = rotAngle;
//angle = mRotation;
Vehicle.Wheels[1].Shape.SteeringAngle = angle;
Vehicle.Wheels[3].Shape.SteeringAngle = angle;
}
Code: Select all
Vehicle.Wheels[1].DrivingMotor.TargetSpeed = ForwardSpeed;
Vehicle.Wheels[3].DrivingMotor.TargetSpeed = ForwardSpeed;
Secondly, if i change method to using pathtfinding like the example I found in the demo, it moves, along the line perfectly, but it never rotates to face the forward direction of the curve, so its like the car moves on its side, then back to its front and so forth.
Where could i be wrong?