Hi, I’m making a 3D space game, and i need i way that if the player’s ship is in range the enemy starbase will fire within an interval between the shots of lasers and torpedoes, but i couldn’t figure out neither of this, someone could help me please?
Do you have some code that need fixing?
actually no, i am still trying to figure out what would be the best way to do it, and how the raycast works
Determine the distance you want the attack to start.
then find the difference between the enemy and player
then check if Some variable is less than the attack distance.
if Some Variable is less than attack distance then fire.
ok, but the starbase i am talking about is cilindrical, how would the atack code be? i mean, since there have to be able to fire in any direction, should i create a barrel within the starbase and rotate it to look at the player or there’s a better way to do?
Use Quaternion.LookRotation(enemy.position - starbase.position) to make the starbase look at the enemy.
you mean this way?
this script is attached to the starbase itself
Instantiate(phaserPrefab, transform.position, Quaternion.LookRotation(player.transform.position - transform.position));
thanks all you guys helping me a lot here
it’s working fine here thanks a lot