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.
Answer by nu-assets · Aug 13, 2016 at 10:16 AM
Your workflow should be as the following:
1) Create a local field variable of type Vector3
private Vector3 LocalHitPoint;
2) Take the world space hit point, transform it to local space and store it in the said variable.
LocalHitPoint = transform.InverseTransformPoint(worldHitPoint);
3) 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.
Your answer

Follow this Question
Related Questions
Game got slow down On iphone 0 Answers
Can anyone make a timer for me? 0 Answers
How can i make an animation like csgo case opening? 2 Answers
How to make a player move up then forward using ontrigger enter collider? 0 Answers
Error BCE0051 with script JS 1 Answer