Get local hitpoint

Today is not my day for scripting -.-

I’ve a problem I can’t get out why it wont work. I guess the solution is simple.

I have an object as a child of a parent. The parent is constantly moving around (and the child with the parent, of course).

Now I let rain particles on the objects surface. All I want is the local hitpoint on the surface of that object for around 2 seconds to adding an effect. The particle gives the hitpoint via intersect-message.

Whatever I try, I just get the global position for 2 seconds (doesn’t move with the object).
So I try to align the HitPosition to the traveling object (script attached to the moving child object):

public var HitPosition: Vector3;

var Hot: boolean;

function Hit(){

    Hot = true;
    
    yield WaitForSeconds(2);

    Hot = false;
        
}

function Update(){

    if(Hot){

        HitPosition = HitPosition + this.gameObject.transform.position;
        
        print("Hit at: " + HitPosition);
             
        Debug.DrawRay(HitPosition, this.transform.forward * 10, Color.red, 2, false);

    }

}

Every help is appreciated.

Your workflow should be as the following:

  1. Create a local field variable of type Vector3

private Vector3 LocalHitPoint;

  1. Take the world space hit point, transform it to local space and store it in the said variable.

LocalHitPoint = transform.InverseTransformPoint(worldHitPoint);

  1. Everytime you need the updated point transform the stored local point back to world space

Vector3 worldPoint = transform.TransformPoint(LocalHitPoint);

This way the initial hit point “follows” your game object. The transform reference is the one of the object that got hit by the particle.