Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

Move a object along a vector

$
0
0
Hello! I am trying to give the enemy movement in the direction of the player using this: transform.position += playerPos.normalized * 10 * Time.deltaTime; Its not working quite well though, the enemy moves in reverse y-direction or something.![alt text][1] This is the rest of the code: using UnityEngine; using System.Collections; public class ninjaScript : MonoBehaviour { //Ninja spawn phase private Vector3 ninjaSpawn; private bool hasSpawned = true; public bool slidDone; public bool hasSlid; public int dice; public float slideSpeed; //Ninja attack phase public bool attackDone; public bool hasAttacked; public Vector3 playerPos; private Vector3 targetPos; void Start () { dice = Random.Range (-3, 3); hasSpawned = true; } void Update () { if (!hasSlid){ slide (); } if (hasSlid){ attackCycle (); } } void slide(){ transform.Translate(0,-slideSpeed*Time.deltaTime,0); if(this.gameObject.transform.position.y < dice){ slidDone = true; } if (slidDone){ hasSlid = true; } } void attackCycle (){ if (!hasAttacked){ attack (); } if (attackDone){ hasAttacked = false; } } void attack () { playerPos = GameObject.FindGameObjectWithTag ("Player").transform.position; transform.position += playerPos.normalized * 10 * Time.deltaTime; } } If someone has any tips id really appretiate it! [1]: /storage/temp/63844-untitled2.png

Viewing all articles
Browse latest Browse all 1488

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>