Recalculating a normal, knowing a local point, on a mesh which moves

Hi everyone !

I have a problem to update datas of a normal, coming from a raycast hit point.
Here is the scene:

i have a door whith a hinge joint.
The player (FPS gameplay), can grab a point on the door and push it.
I use a raycast to see where the door was hit, i store:

  • Hit Point Position
  • Hit Point Normal

The player then applie a force on the point, following the normal.
But i would like to update the normal (because the door rotate) whithout using a new raycast.
I still know the local position of the first hit,
isn’t there any method to recalculate its normal ?

Thank you for reading ! :slight_smile:
PS: Excuse me if my english is inacurate…

Djor

Maths… yay… I suck at it but I’d investigate something like this

(previousDoorRotation - currentDoorRotation) gives you the amount the door has rotated… now you just gotta figure out how to rotate the hit normal you’ve stored…

Good luck :slight_smile:

Hey Trooper, Thank you for answering !

You’re close :wink:
It is currentAngle - initialAngle etc…
Now my normal vector follow the door movement !

var quat : Quaternion = Quaternion.Euler(0,objectHandled.transform.eulerAngles.y-initialAngleDoor,0);
var newvect = quat * hitNormal;

I have a strange behavior now, in some cases, when i push the mouse, it pushe the door, but at some angles, commands just invert…
I’ll check why and give explanation here when i find !


Ok, now, i found why i had this problem, if this can help someone someday :slight_smile:
I was using :

objectHandled.rigidbody.AddForceAtPosition(newvect * Input.GetAxis("Mouse Y") * -15, hitPoint);

instead of the working :

objectHandled.rigidbody.AddForceAtPosition(newvect * Input.GetAxis("Mouse Y") * -15, objectHandled.transform.TransformPoint(hitPoint));

I was applying my vector (updated in time thanks to trooper !), in a point taken in local space,
with my new line i translate my local space point to world space point.
It now works :wink: !