Before starting, yes I have seen this question Realistic rotation of flying arrow? - Questions & Answers - Unity Discussions but the solutions suggested there are not working for me.
I have a script to shoot. Muzzle is an empty GameObject with the point where the bullet will be fired from. I apply a rotation because the arrow is in vertical when I instatiate it.
using UnityEngine;
public class Shoot : MonoBehaviour
{
public Transform muzzle;
public Rigidbody bullet;
public void Update()
{
if (Input.GetMouseButtonDown(0))
{
Rigidbody b = GameObject.Instantiate(bullet, muzzle.position, muzzle.rotation) as Rigidbody;
b.transform.Rotate(90, 0, 0);
b.AddForce(b.transform.up * 500);
}
}
}
I tried both solutions suggested in the first link to control the arrow rotation, but it doesn’t fly the way one should expect. The arrow doesn’t keep the initial rotation and reorients itself in a wrong way. The script attached to the arrow is this:
using UnityEngine;
public class ArrowControl : MonoBehaviour
{
public void Start()
{
GameObject.Destroy(gameObject, 10);
}
public void Update()
{
transform.forward = Vector3.Slerp(transform.forward, rigidbody.velocity.normalized, 10 * Time.deltaTime);
//rigidbody.rotation = Quaternion.LookRotation(rigidbody.velocity);
}
}
Any suggestion to make the arrow behave properly during the flight?