- Home /
enemy shakes when it gets to a certin position
i dont know a lot about unity but im trying to make a game and the enemy has a speacial attack and this is how it should work . if the enemy felt the player he will fly then a danger zone appers then the enemy have to go fast into the danger zone . if the player touches the player he dies . porblem is that when the enemy went into the zone . he started to shake in the x axis heres the attacking part to the enemys AI hope someone responds fast using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Enemy : MonoBehaviour {
public GameObject dangerzone;
private Vector2 movement;
private Rigidbody2D rb;
private void Start(){
rb = GetComponent<Rigidbody2D>();
}
private void Update(){
Vector3 direction = dangerzone.transform.position - transform.position;
direction.Normalize ();
movement = direction;
dash (movement);
}
void dash(Vector2 direction){
rb.MovePosition ((Vector2)transform.position + direction * 6 * Time.deltaTime);
}
}
Your answer
Follow this Question
Related Questions
How do I flip an enemy that's automatically walking and targeting the player? 1 Answer
My enemy gameobjects are merging into one when I want them to follow me in 2D, need some help. 1 Answer
Astar Pathfinding with unity 2d 1 Answer
Following the newly created object 2 Answers
"the object of type transform has been destroyed but you are still trying to access it" problem, 1 Answer