Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to attach a ray cast hit point to a hit object?

Discussion in 'Scripting' started by MadeByJ, Nov 19, 2022.

  1. MadeByJ

    MadeByJ

    Joined:
    Nov 9, 2022
    Posts:
    2
    Hi I am working on a project where I have cubes floating around the scene, I have used a YouTube tutorial to make a grappling hook script that shoots out a ray cast to create a grapple point which works well for stationary objects but when shooting a moving object the object moves away leaving the grapple point floating in the air.

    I was wondering if anyone had any suggestions as to how I would attach the result of the ray cast hit to the GameObject it collides with so the grapple point stays with the moving cube.

    Thanks,
    Joe
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    If it has to be a coordinate only, you could probably do some other trickery to apply the same movement as the object you attached to. However, why not simply create a gameobject at that location. You can now easily make it the child of the hit object and use its world position as anchor position for your grapple. Now if the parent moves, your attachment point moves too.
     
  3. MadeByJ

    MadeByJ

    Joined:
    Nov 9, 2022
    Posts:
    2
    Hey thanks for the reply I will give that a go tonight and see if it works.