Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

ajust AI movement to aim player

Discussion in 'Editor & General Support' started by Wonsder, Apr 6, 2020.

  1. Wonsder

    Wonsder

    Joined:
    Jan 24, 2020
    Posts:
    37
    Hi all, don't really know where to post this.
    sorry if I make any language mistakes, my english isn't that good...

    I've tried things by miself a bit, but couldn't manage to do it properly (there are still bugs, or not working at all)

    Basically, i have a player fighting combat robots, and one of the robot's attack is to activate jet engines and rush the player. I've got most of it working, but I would like to allow the robot to sligthly correct it's trajectory towards the player, since it's way too easy to dodge for now.

    The robot charge direction is stored in a Vector3, and i would like to redierect this vector by a max angle towards the vector difference between the player and the robot (so where the player is from the robot), didn't know is that was clear...

    I would like to do this both in 2d and 3d if possible.

    any ideas of a good way to do this ?
     
  2. Wonsder

    Wonsder

    Joined:
    Jan 24, 2020
    Posts:
    37
    I think I've got something working, but don't know if the maths are correct, because i don't really understand multiplying vectors and questernions.

    what I am doing :

    get angle between aimDirection and currentDirection,
    clamp that angle between min and max authorized angle,
    get the rotation axis with vector.cross(aimDirection, currentDirection)

    and this is the thing I don't understand :

    newDirection = Quaternion.AngleAxis(angle, rotationAxis) * currentDIrection

    Any explanations ?

    Also this does not work so well, I'm getting weird things like my robot doing full 180