Hello. I want to create a swinging mechanic like this, where hook shoots out from the player at a 45 degree angle and the character can swing on it (my game idea is also 2D). Anyways, after asking around, I was told that a way I could accomplish this was to use Plane.Raycast from the player character, check to see if the ray hits an object that the player is able to hook onto, and have my hinge joint put there, how would I do this? specifically, how would I use the raycast to check the object it may be hitting and then, move my hinge to that point?
Answer by efge
Feb 23, 2011 at 12:29 PM
I would suggest to use Physics.Raycast instead of the (limited) Plane.Raycast, because you can get all necessary information from RaycastHit.
Especially for placing the joint you get RaycastHit.point and RaycastHit.normal.
Okay, how would I do that?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
Raycast stop at distance
Add force on click from cameras point of view
Raycast Car Physics
Detect which object is clicked with RayCast
Raycast doesnt detect object in front of rigidbody (player is stuck on wall)