#rotation smoothing or smt

1 messages · Page 1 of 1 (latest)

sturdy raven
#
{
    public float gravity = -10f;
    
    public void Attract(Transform body)
    {
        Vector3 targetDir = (body.position - transform.position).normalized;
        Vector3 bodyUp = body.up;

        body.rotation = Quaternion.FromToRotation(bodyUp, targetDir) * body.rotation;
        body.GetComponent<Rigidbody>().AddForce(targetDir * gravity);
    }
}
#

i have not really used lerps yet but yeah that is why i am asking but i am not even sure if that is what i should use here?

#

i just tried doing this but it doesnt seem to work: ```using UnityEngine;

public class GravityAttractor : MonoBehaviour
{
public float gravity = -10f;

public void Attract(Transform body)
{
    Vector3 targetDir = (body.position - transform.position).normalized;
    Vector3 bodyUp = body.up;
    Quaternion.Slerp(body.rotation, Quaternion.FromToRotation(bodyUp, targetDir), 0.1f);
    //body.rotation = Quaternion.FromToRotation(bodyUp, targetDir) * body.rotation;
    body.GetComponent<Rigidbody>().AddForce(targetDir * gravity);
}

}

#
    public float gravity = -10f;
    
    public void Attract(Transform body)
    {
        Vector3 targetDir = (body.position - transform.position).normalized;
        Vector3 bodyUp = body.up;
        body.rotation = Quaternion.Slerp(body.rotation, Quaternion.FromToRotation(bodyUp, targetDir), 1.5f);
        //body.rotation = Quaternion.FromToRotation(bodyUp, targetDir) * body.rotation;
        body.GetComponent<Rigidbody>().AddForce(targetDir * gravity);
    }
}
``` okay i didnt assign it but now it glitches