I’m trying to make a homing attack for my spinning tops. The spinning tops knows where to aim as I’ve tagged the enemies and it moves using the rigidbody.AddForce function. but it only ever moves in one direction and never towards the enemy spinning top here’s the code I am trying to do it with P.s really new to programming ;
using UnityEngine;
using System.Collections;
public class Homingattack : MonoBehaviour {
public GameObject target;
public float speed = 1;
void Start ()
{
target = GameObject.FindGameObjectWithTag ("SpinningTopCPU");
}
void Update()
{
if (Input.GetKeyDown (KeyCode.Z)) {
rigidbody.AddForce(target.transform.position *speed*50);
rigidbody.useGravity = true ;
}
}
}