- Home /
How can I make the gun rotate and shoot like lost control and shooting all around ?
The shooting part I will make later. Now I'm trying to make the rotations part.
The first thing I did is to rotate the gun barrel and this is working fine. The next thing I want to do is to rotate the gun body 360 degrees randomly so when the gun will shoot it will shoot randomly all around like lost control.
This is a screenshot of the gun barrel :
And the gun body :
By rotating the gun body 360 degrees randomly I want to create a lost control effect so it will shoot all around hitting randomly.
The script is attached to the top parent Drone :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour
{
public Transform[] wings;
public Transform[] propellers;
public Transform gunBarrel;
public Transform gunBody;
public float propellersSpinSpeed = 50;
public float wingsSpinSpeed = 50;
public float gunBarrelSpeed = 50;
private float angle = 360.0f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
for (int i = 0; i < propellers.Length; i++)
{
propellers[i].Rotate(0, propellersSpinSpeed * Time.deltaTime, 0);
}
for (int i = 0; i < wings.Length; i++)
{
wings[i].Rotate(0, wingsSpinSpeed * Time.deltaTime, 0);
}
gunBarrel.Rotate(0, 30 * gunBarrelSpeed * Time.deltaTime, 0);
gunBody.Rotate(Vector3.zero, angle * Time.deltaTime / 1.0f);
}
}
I tried to do :
gunBody.Rotate(Vector3.zero, angle * Time.deltaTime / 1.0f);
But it does nothing not rotating it 360 degrees and I didn't use yet the Random. The gun barrel keep rotating but the lost control shooting all around is not working yet not sure how to do it.
Your answer
Follow this Question
Related Questions
How can i rotate object smooth without stop ? 2 Answers
Multiple Cars not working 1 Answer
transform.Rotate will not work 1 Answer
Distribute terrain in zones 3 Answers
Why the player is not rotating and moving at the same time ? 0 Answers