Raycast in front of player (or car) to determine how close something is?
I can't seem to get this to work. Any help is appreciated. For now I'm just trying to cast a ray in the forward direction of the player, draw a little marker there, and return the distance to the first thing it intersects with.
Ped player = Game.Player.Character;
Vector3 source = player.Position;
// get 5 units in front of player
Vector3 direction = source + Game.Player.Character.ForwardVector * 25f;
RaycastResult rc = World.Raycast(source, direction, IntersectOptions.Everything);
World.DrawMarker(MarkerType.VerticalCylinder, rc.HitCoords, Vector3.Zero, Vector3.Zero, new Vector3(1f, 1f, 1f), Color.Yellow);
Sorry to do this, but anyone have an idea?
I think direction should just be
Game.Player.Character.ForwardVector(don't add source or multiply).
Ah that's it, thank you!