29 lines
878 B
C#
29 lines
878 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class HandPresencePhysics : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
private Rigidbody rb;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
rb = GetComponent<Rigidbody>();
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void FixedUpdate()
|
|
{
|
|
//position
|
|
rb.velocity = (target.position - transform.position) / Time.fixedDeltaTime;
|
|
|
|
//rotation
|
|
Quaternion rotationDifference = target.rotation * Quaternion.Inverse(transform.rotation);
|
|
rotationDifference.ToAngleAxis(out float angleInDegree, out Vector3 rotationAxis);
|
|
|
|
Vector3 rotationDifferenceInDegree = angleInDegree * rotationAxis;
|
|
rb.angularVelocity = (rotationDifferenceInDegree * Mathf.Deg2Rad / Time.fixedDeltaTime);
|
|
}
|
|
}
|