Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by A-man tuna · Jun 29, 2015 at 12:33 AM · javascriptraycastlinerenderer

Grapple Gun?

I've been looking for a script to create a grappling hook on the internet but all of the codes seem a little too complicated. What i want to do is to be able to only click on certain gameobjects that allow the grappling hooks to attatch onto and retract the player to that position. I'm pretty sure I have to use a raycast to see where the grapple hook has to go, and also a line renderer to create the rope for the grapple hook. But i'm really not sure about how to combine these and how to retract the player to the position. I'm a bit of a noob to coding so some description of the code would be really helpful as well.

Thanks In advance

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by The-Game-Master · Jun 29, 2015 at 12:47 AM

Although I'm not exactly sure how to do it, I'd imagine it'd have to do with Vector3.MoveTowards(). You could do the following:

  1. Raycast when the mouse is clicked (or however you do it)

  2. Get the gameObject's tag from the raycast.hit information

  3. if the tag is an allowed surface to grapple onto, use Vector3.MoveTowards(transform.position, RaycastHit.transform.position);

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image A-man tuna · Jun 29, 2015 at 07:52 AM 0
Share

Interesting! $$anonymous$$y player also has a constant force added onto him, would this affect the way he moves after grappling? also after he reaches the grappled position would he still be able to continue moving or would he still be stuck at the grapple's final position? But thanks for the answer that actually helps quite a lot :)

avatar image The-Game-Master · Jun 29, 2015 at 04:21 PM 0
Share

No problem! If you wanted the player to be stuck until he hits a key, you could just use an if statement and a boolean. That boolean would be false until the key is pressed, then the boolean would be true. While the boolean is false, it would disable the character controller script, and once it is true, it would re-enable the character controller.

avatar image The-Game-Master · Jun 29, 2015 at 04:33 PM 0
Share

And no, it does not effect the player's movement after the grapple is released. (to release the grapple after the player reaches the spot, use this:)

         if(Vector3.Distance(transform.position, RaycastHit.transform.position) >= 1){
             if($$anonymous$$ovePlayer == true){
                 Vector3.$$anonymous$$oveTowards(transform.position, RaycastHit.transform.position, .07f);
             }
         }
         else{
             $$anonymous$$ovePlayer = false;
         }

That way, the grapple would only move the player if they're more than 1 unit away from the raycast hit. Then, it would set the bool to false, and it would stop moving you.

avatar image A-man tuna · Jun 29, 2015 at 08:18 PM 0
Share

Wow thats super helpful! I'll try it out soon and let you know how it goes :)

avatar image The-Game-Master · Jul 01, 2015 at 08:19 PM 0
Share

You're welcome! Sidenote: While grappling, you may want to disable the player's movement script, that way they can't fall, and they can't move while in the air.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Raycast Tag of Hit GameObject 1 Answer

Raycast to Terrain (Conditional Statements) 1 Answer

raycast to object, load wrong script!? 2 Answers

Help with LineRenderer 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges