- Home /
Runny Turret Shot (Android)
Hey Unity Community,
i need your held. I'm building a tower defense and hbae following problem. The shots of the towers skip whole frames and are only behind the enemies Visible, they do not meet, what can I do that will always hit the opponent? this is the Turret script fire mehode
void FireProjectile(){
Rigidbody clone;
for(int i = 0;i< muzzlePositions.Length;i++){
Transform theMuzzlePos = muzzlePositions[i];
clone = ((GameObject)Instantiate(myProjectile, theMuzzlePos.position, theMuzzlePos.rotation)).rigidbody;
clone.GetComponent<Projectile_Cannon>().target = hit.point;
}
}
and here the Projetctil
public class Projectile_Cannon : MonoBehaviour {
public float mySpeed = 10;
public float myRange = 10;
public Vector3 target;
private float myDist;
void Update () {
/**transform.Translate(Vector3.forward * Time.deltaTime * mySpeed);
myDist += Time.deltaTime * mySpeed;
if(myDist >= myRange)
Destroy(gameObject);
**/
transform.position = Vector3.MoveTowards(transform.position, target, mySpeed * Time.deltaTime);
}
void OnCollisionEnter(Collision collision){
if(collision.gameObject.tag == "Enemy"){
Destroy(gameObject);
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613120645im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lock rotation of object 4 Answers
Turret bullet rotation problem 1 Answer
instantiate works on one but not other object 0 Answers
turret shoot if in range 1 Answer
Turret targeting is wrong 1 Answer