Fixed player location calculation via camera trigger collider
This commit is contained in:
28
Assets/HandPresencePhysics.cs
Normal file
28
Assets/HandPresencePhysics.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user