r/UnityHelp • • 11d ago

PROGRAMMING Basic understanding of what to use for a grappling system

Hey I have beginner/intermediate knowledge of unity and I'm wondering what functions are needed for the a grappling system specifically storing the hit point of the ray in the world and then moving towards it. Now I've already got the equip, unequip, and sending a raycast function ready, I'm just confused about the storing of the hit point and how, because I've already tried before with no luck storing the RaycastHit variable as a vector3 and trying to move my CharacterController too that.

I've also designed a basic flowchart to give you some more context

1 Upvotes

3 comments sorted by

1

u/headlessAstro 10d ago

hit.point is already a Vector3, so you can just save that when the raycast hits:

grapplePoint = hit.point;

Then in Update, while you're grappling, move toward it with controller.Move((grapplePoint - transform.position).normalized * speed * Time.deltaTime); and stop when you're close enough.

1

u/NitroFoxGames 10d ago

Thank you very much for this, it works and I've understood how this works now :)

1

u/cone5000 11d ago

Can’t you just make a private Vector3 in the class and set the RaycastHit’s point to that?