So atm I am going through a course on Udemy. In one Example we create a small boss fight in where a turret shoots cannonballs at the player. The cannonball is a prefab which has force added to it on Awake()
just look here:
void Awake()
{
this.GetComponent<Rigidbody> ().AddRelativeForce (new Vector3 (0, GetRandomValue(), GetRandomValue()));
this.GetComponent<AudioSource> ().PlayOneShot (audioShoot);
}
The Boss is following the player and using the Instantiate() function to add the rotation and position to the object just look here:
void Update()
{
FollowPlayer ();
Shoot ();
}
void FollowPlayer()
{
this.transform.LookAt (player);
}
void Shoot ()
{
if ( Time.time > lastTime + delayTime )
{
lastTime = Time.time;
delayTime = GetRandomValue ();
GameObject obj = Instantiate ( cannonball, this.transform.position, this.transform.rotation );
obj.name = "Cannonball";
}
}
The problem is that the cannonball always shoots in the same dircetion, but if i replace Awake() with Start() it shoots where the player is.
EDIT: So I just downloaded the whole project he made in his course and the problem persists. Unity must have made some changes that affect Awake() or something because in his course I can clearly see the Boss shooting the cannonball at him and not in the same direction. Any idea why Awake() doesn’t work but Start() does? Why are my parameters overwritten by standart values when using Awake() but not when using Start()? Start() must come later than Awake() that I am certain