How to use(in raycast) the transform of a child when the parent moves?

Hi,

I’m using a boat with a boyancy script. I need to be able to click on few object wich are parented to the boat.

I’m using the raycast demo
so basicaly :

 public Transform target1;


       if (Input.GetButtonUp("Fire1"))
        {

            if (Time.time - lastClick < 0.3)
            {


                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.transform == target1)
                    {

It seems that I can use that raycast on the object and I suppose that it’s coming from the fact that the childs transform doesn’t move.

Is there a better way to do clickable object in this case ? or should I create a script wich link the transforms of my objects to the transform of the parent?

Thank’s for the help

BooBi

A few questions would bear a better understanding of what you are doing. Are these objects on the players boat, or are they objects on the enemy boat? Game wise, what is the overall process in which you want to use the click? Are you just wanting the player to click on something, or is it a specific place?

Try this:

Apply a OnMouseDown event to specific objects. This will happen when someone clicks on a collider. That will get the object in question. IF… you just want to select the boat, put the OnMouseDown event on the boat, then all it’s colliders, regardless of where they are in the hierarchy will cause the event. (you can also do both: I clicked on the back crate that is in this boat)

Next, in the OnMouseDown event, you can do a Physics.Raycast from the screen to figure exactly where the user clicked. (if needed)

I finally linked my object with a script like that:

Child.position = parent.position;
Child.rotation = parent.rotation;

and it works…

But I’m sure that I can optimise that by using another way (I’ll try that tomorrow).

What I’m doing is a visualisation of a boat (a catamaran), with clickable point (determinated by few red “blinking” spheres). I’m using the community ocean so the boat moves on the water.
I’m using a box to have a nice movement on the water (this box recover the surface of my boat (the two hulls)).

When you click on a sphere, I’ve got a sliding panel at the right of the screen wich display info about that part of the boat.

That’s the project.

I’ll check tomorrow for a more optimized way to do it.
But thank’s again for your help mate !

Oh yeah, for that, simply apply a OnMouseDown to each object and set some variable in a GUI script that will accomplish your GUI functions.

GUI sliding should be a simple task, as you start off defining a block GUI objects and just move the block on and off the screen as needed.

It should be a very interesting project.

Thanks for sharing.

The on mousedown won’t work, because i’m using a double click on the sphere (i forgot to explain that part ^^ ) because the simple clic is quite continuously use to rotate around the boat.

But I can use my piece of script to do the dble click on the object. How would you do that ? with a ontrigger function?

I’m going to look in my old scripts I’m sure I’ve done that before ^^

And the sliding panel is done you helped me yesterday with the “Lerp during 2 seconds”