- Home /
How to use a Vector3.MoveTowards and the resulting position as an input for a normalised BlendTree
Hi for a group project I am making a game but I can't figure out how to properly use the Vector3.MoveFunction to make the resulting vector be the correct input for my blend tree that I've set up. Here is some code that I have so far and I tried getting the angle between the target and the gameObject (which is an enemy that chasing after the player that is the target), which then gets converted into a normalised input on the X and Y axis on a Vector3 movement that gets inputted to the blend tree (which is used for the enemy gameObjects directional movement, I cannot use input.GetAxis due it being controlled by simply chasing after the player gameObject).
transform.position = Vector3.MoveTowards(transform.position,
target.transform.position,
chaseSpeed * Time.deltaTime);
angle = Vector3.Angle(transform.position, target.transform.position);
movement.x = Mathf.Cos(angle);
movement.y = Mathf.Sin(angle);
animator.SetFloat("Horizontal", movement.normalized.x);
animator.SetFloat("Vertical", movement.normalized.y);
The functions above are inside an Update function currently the input is just making the input basically cause the movement animations to almost go in circles no matter what direction they are moving in.
Your answer
Follow this Question
Related Questions
Problem with Vector3 position. 1 Answer
fixed distance for Vector3.moveTowards ? 1 Answer
Instantiate object in front of player? 2 Answers
collider triggers transform position 1 Answer
Move an object to Input.Touch location 0 Answers