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

Vector3 MoveTowards character flying up when told to follow,Vector3 MoveTowards object flying up when I press play

$
0
0
I have my "enemy" following another "enemy", yet instead of following, it flies up in the air right off the bat and moves on all the axis. public class BASICMOVEMENT : MonoBehaviour { Vector3 targetpos; bool enemyseen; object target; public float movspeed = 1f; public float step; bool inAttackRange; // Start is called before the first frame update void Start() { enemyseen = false; } // Update is called once per frame void FixedUpdate() { Vector3 fwd = transform.TransformDirection(Vector3.forward); RaycastHit RCC; if (Physics.Raycast(transform.position, fwd, out RCC, 10)) { if (RCC.collider.name == "hitbox") { enemyseen = true; target = RCC.collider.transform.parent.gameObject; targetpos = RCC.collider.transform.position; Debug.Log(RCC.distance); if (RCC.distance < 0.5) { inAttackRange = true; } } } } void Update() { if (enemyseen == true) { /*StartCoroutine(Attack());*/ if (inAttackRange == false) { step = movspeed * Time.deltaTime; this.transform.parent.gameObject.transform.position = Vector3.MoveTowards(transform.position, new Vector3(targetpos.x, transform.position.y, targetpos.z), step); } } } }

Viewing all articles
Browse latest Browse all 1488

Trending Articles



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