Search Unity

Question SamplePosition gives random positions and agent doesnt go straight

Discussion in 'Navigation' started by NewMagic-Studio, Jul 13, 2020.

  1. NewMagic-Studio

    NewMagic-Studio

    Joined:
    Feb 25, 2015
    Posts:
    454
    When i use the target player with an obstacle carving dynamic the enemy agent doesnt go straight, it goes rotating from one steeringpoint to another which is not a straight path, but makes like small rotations as if there was a curve. Tried using SamplePosition, adding to the player position, the normalized vector difference between the player and the enemy multiplied by the player obstacle radius, and instantiating a cube for debugging purposes, but i realized that cubes appear a bit to the right of the player or a bit left, but not in the direction to enemy exactly as if that position were not valid and picked something close, and in that way the enemy pass left or right the player but doesnt go in front of player exactly. Also sometimes appear the cube right and left randomly. Any ideas?

    I use this

    if (NavMesh.SamplePosition(PlayerManagement.Instance.playerGround + (transform.position - PlayerManagement.Instance.playerGround).normalized * 0.3f, out hitNav, 0.4f, NavMesh.AllAreas))
     
    Last edited: Jul 13, 2020