I went ahead and searched the forum and found a similar topic but it doesn't seem to have fixed my problem. I am trying to rotate an NPC CharacterController towards an entity and then move towards it.
I have the following code inside the NPC CharacterController's update function:
Code: Select all
Vector3 currentPosition = character.Body.Position;
Vector3 positionToFace = player.Body.Position;
Vector3 difference = positionToFace - currentPosition;
character.ViewDirection = difference;
character.HorizontalMotionConstraint.MovementDirection = Vector2.Normalize(new Vector2(difference.Y, difference.Z));
Code: Select all
Game.LineDrawer.LightingEnabled = false;
Game.LineDrawer.VertexColorEnabled = true;
Game.LineDrawer.World = Microsoft.Xna.Framework.Matrix.Identity;
Game.LineDrawer.View = MathConverter.Convert(Game.Camera.ViewMatrix);
Game.LineDrawer.Projection = MathConverter.Convert(Game.Camera.ProjectionMatrix);
Game.GraphicsDevice.BlendState = BlendState.Opaque;
Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
foreach (var pass in Game.LineDrawer.CurrentTechnique.Passes)
{
pass.Apply();
Game.GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList,
new[]
{
new VertexPositionColor(character.Body.Position, Microsoft.Xna.Framework.Color.Blue),
new VertexPositionColor(character.ViewDirection + character.Body.Position, Microsoft.Xna.Framework.Color.Blue)
},
0, 1);
}
Edit: I tried swapping around X,Y, and Z for
Code: Select all
Vector2.Normalize(new Vector2(difference.Y, difference.Z))
Thanks.