- Home /
Question by
gamedevunity12 · Jan 24, 2021 at 08:30 AM ·
projectiles
rotations of gameobjects
can someone have a look at this for me please. The rotation should not happen instantly at the start it should be gradual, at the moment my rocket just turns as soon as a I press "Fire1". To see what I mean, put the script on an empty game object with -30 on the x rotation. And add a projectile as child and align it with the rotation of the parent empty.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Zfwd : MonoBehaviour
{
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = false;
}
private void Update()
{
if (Input.GetButtonDown("Fire1"))
{
transform.rotation = Quaternion.LookRotation(rb.velocity);
rb.AddForce(transform.forward * 2000);
rb.useGravity = true;
}
}
}
Comment