I’m using unity3d 2022.3.10f and I am trying to work out how accurate someone hits an object with the controller in a VR game I am doing for the oculus.
To simplify this so I can test repeatedly with various scenarios, I have a static object (sphere) that has a collider on it. I have a 2nd object (another sphere) that also has a collider on it.
They are directly inline with each other e.g.
Sphere 1: is at 0,1,1
Sphere 2: is at 0,1,0
So they are 1 distance on the z axis.
I then impart a velocity to sphere 2 to send it exactly towards Sphere 1 (0,0,1). When the colliders trigger – I want a % rating of how accurate they collided – basically projecting the center of sphere 2 on its path to see how close it would have come to hitting the center of sphere 1.
In my above example I would expect a % of 100% as they were on exact collision course.
If I then change the velocity imparted on Sphere 2 to make it still collide but very slightly offline i.e. velocity of (0,0.04,1) – I would expect a lower % value e.g. 75% and so on to a % of near 0 if they just about scrape when then hit.
I have tried many different ways but unable to come up with anything.
Has anyone got code to do this they could share?
Thank you for your time.
R