How to set the speed of a randomly rotating object
I want to add speed to random rotating cannon here is the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyCannonManager : MonoBehaviour
{
public GameObject ball;
public float lunchForce;
public Transform shotPoint;
void Update()
{
Vector3 euler = transform.eulerAngles;
euler.z = Random.Range(-20f, 20f);
transform.eulerAngles = euler;
if (Input.GetMouseButtonDown(0))
{
Shoot();
}
}
void Shoot()
{
GameObject newBall = Instantiate(ball, shotPoint.position, shotPoint.rotation);
newBall.GetComponent<Rigidbody2D>().velocity = transform.right * lunchForce;
}
}
Comment
Your answer
