Hello all,
Currently I have a project setup with SteamVR and VRTK plugin. I pickup an object (an axe) using VRTK which is snapped onto a joint, connecting to the Vive controller. I have a script attached to the axe that will record it’s speed and velocity:
public float speed = 0;
Vector3 lastPosition = Vector3.zero;
public Vector3 velocity = Vector3.zero;
void Update()
{
speed = (((transform.position - lastPosition).magnitude) / Time.deltaTime);
lastPosition = transform.position;
velocity = (transform.position - Vector3.zero) / Time.deltaTime;
}
Now, I have a Log object with a Rigidbody and colliders, it also has a script to handle collisions:
void OnTriggerEnter(Collider collider)
{
if (!collider.gameObject.CompareTag("Blade"))
{
return;
}
Blade blade = collider.gameObject.GetComponentInParent<Blade>();
if (blade.iObject.IsGrabbed() && blade.speed > 10.0f)
{
mRidgidBody.AddForce(blade. velocity * (blade.speed / 1));
}
}
I’ve tried assigning the velocity of mRidgidBody as well as AddForce in the code above, but it seems there is a problem with the tracking of the axe blade’s velocity when the Log is hit, it always adds force in one direction.
Any suggestion would be appreciated.
EDIT: I was using Vector3.zero in the velocity, when I use lastPosition the Log doesn’t react to the force applied.