Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Mar 15, 2017 at 11:05 PM by Nova-1504 for the following reason:

Other

avatar image
0
Question by Nova-1504 · Mar 15, 2017 at 02:15 PM · errorphysicsraycastinggrappling gunhook

How do i make a simple grappling hook?

I want to make a simple grappling hook (right mouse to fire, 1 to reel in, 2 to reel out, C#). I found this: link but the script gives me an error (well, four) saying x, y and z don't exist and int can't be converted to Vector3. I know x, y and z aren't correct but I don't know what goes there. Can someone either (A) Tell me how to fix it or (B) Direct me to a different tutorial, preferably (but not necessary) involving raycasting?

EDIT Ok, I attached the script to a cube, parented it to the player and it does - NOTHING! Cube doesn't move, no "Grappling" effect. That's because I need (A) A script to make it so that however far away the player is from the point of impact, the player stays that far away and (B) The cube needs to actually move. HELP!?

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GrapplingHook : MonoBehaviour {
 
     private bool inAir = false;
     private HingeJoint grabHinge;
     public int speed;
     Rigidbody rb;
 
     void Awake () {
         rb = GetComponent<Rigidbody> ();
     }
     void Update () {
         if (Input.GetButtonDown("Fire2")) {
             GrapplingShot ();
         }
     }
     //To shoot your hook, call this method:
     void GrapplingShot(){
         rb.velocity = this.transform.forward * speed;
         inAir = true;
         //This is the direction your hook moves multiplied by speed.
         }
 
     void OnCollisionEnter (Collision col) {
         if (inAir == true) {
             rb.velocity = Vector3.zero;
             inAir = false;
             grabHinge = gameObject.AddComponent <HingeJoint>();
             grabHinge.connectedBody = col.rigidbody;
             //This stops the hook once it collides with something, and creates a HingeJoint to the object it collided with.
         }
     }
 }
 


Comment
Add comment · Show 5
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 TreyH · Mar 15, 2017 at 02:33 PM 0
Share

Well, they aren't defined. It sounds like the goal is to fire something in the direction your character is facing? If that's the case, then you could probably do:

 void GrapplingShot(){
  rigidbody.velocity = this.transform.forward * speed;
  inAir = true;
  //This is the direction your hook moves multiplied by speed.
  }
avatar image TreyH · Mar 15, 2017 at 02:34 PM 0
Share

But, that example is really more pseudo-code than a working example. Very little is declared explicitly, and the ".rigidbody" property has been deprecated.

avatar image Nova-1504 TreyH · Mar 15, 2017 at 02:44 PM 0
Share

Ok, the xyz errors are gone, do you know anything about this? alt text

capture.png (4.4 kB)
avatar image TreyH Nova-1504 · Mar 15, 2017 at 02:46 PM 0
Share

Taking a guess:

 rigidbody.velocity = 0;

swap that for

  rigidbody.velocity = Vector3.zero;

avatar image Nova-1504 · Mar 15, 2017 at 02:51 PM 0
Share

Errors are gone! Thanks, i'll let you know how it works.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

114 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 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

How do I solve this error? 2 Answers

Invalid AABB Error on collision :( 1 Answer

Physics.Boxcast not working with mesh collider 1 Answer

How to move a Sphere using physics 0 Answers

Error: NpRigidDynamic::isSleeping: Body must be in a scene. 1 Answer


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