Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
5
Question by Undeleted · Oct 17, 2013 at 02:55 AM · javascriptaddforce

Help with coding a simple grapple system - javascript

I don't have much experience coding in java, but I'm familiar with coding itself, as I'm an expert at actionscript3. I need to make a simple-ish dual grapple system (as seen in "Attack on Titan" see link---> 3D Maneuver Gear - Grapple system in action - jpeg) to move around an environment.

I'm planning on using a rope prefab, basically a thin and long cylinder that you can adjust the length of with code, and a third-person character prefab. So here's how this will work:

  1. the player's grapple gun is point A. When a button is pressed, the rope prefab appears in the direction of the crosshair and plays an animation of a shot. the length of rope prefab is always in front of the gun itself, but i think that can be handled with animations.

  2. when (and if) the prefab hits a tagged object, it replaces itself with another of the same rope prefab that connects point A (the grapple gun) to point B (the object). this new prefab is the same prefab from before, but the length is the distance from point A to point B and there are no active animations.

  3. next, force is applied to the player in the direction of point B, but the force is included with (or "on top of") all the other forces affecting the player (wind, jumping or running, explosions, the player's own weight/gravity, etc), and the player (which the grapple gun is a child of) is moved along the rope prefab to point B. All the while, the rope is getting shorter by frame according to the player's distance from A to B. (this can be set by one line of code updating each frame, or a function executing only when grapple key is pressed to when point B is reached)

//note that point A will always be the gun, and point B will always be a tagged object.

I just need a little bit of pointers in the right direction, if this is possible or not, if some elements should be revised or scrapped. If it's possible, actual code will help alot. Note that the verbal schematic is only for one grapple gun, and there will be two per player, so the variables might need to be named accordingly. The gun is a child of the player, not the player itself.

Thanks for any feedback

Comment
Add comment · Show 3
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 Benproductions1 · Oct 18, 2013 at 01:35 AM 0
Share

Note, that "Java" is not the same as "Javascript". They are two completely different program$$anonymous$$g langes and should not be confused with oneanother :)

ALso when making references, it's good to show a link or something. Just saying "like Attack on Titan" will not help someone understand it. Post an image or something, or even link a video ;)

avatar image Undeleted · Oct 18, 2013 at 02:10 AM 1
Share

just added one, thanks for the re$$anonymous$$der

avatar image Benproductions1 · Oct 18, 2013 at 03:09 AM 0
Share
  • for good question and the fact you edited ins$$anonymous$$d of posting a comment
    Users who do good should get rewarded properly :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by skylem · Jan 19, 2015 at 07:42 AM

K fellow here it is Some Pointers hope i provide enough, if i were to make a grapple system i would first ask myself the question of how im going to achieve this and discern what objects/how many and there components i might need to do this So after about 30 seconds Heres a rough concept for the Grapple System This is Only examples of the code you may need/wish to use, as to write the entire script would probably take me several hours Good Luck i hope it all helps.

 Transform grappleHook; //Reference your hook
 Transform character; //Reference what ur dragging
 bool fired; // check if you fired the hook
 bool madeContact; // check if the hook made contact
 RaycastHit hit1 = new RaycastHit();  // create a raycast for the contact point this is set by out below
 Vector3 CollPoint1 = grappleHook.transform.TransformPoint( grappleHook.center ); // create and set vector3 for the raycast    
         if( Physics.Raycast( CollPoint1, out hit1, 1f )) { 
  madeContact = true;
 }
 
 //check a keypress to shoot it 
     if(Input.GetKeyDown(Keycode.Space)) {    
 fired = true;
 }
 // use them together to create your own function
 if(fired && madeContact) {
    GrappleHook();
 }
 
 // use this function to move check the distance between the object ur moving and your contact point.
 
 void GrappleHook() {
 float distance = Vector3.Distance(hit1.transform.position, character.transform.position)
 // use the distance to say the character should move toward the hit point
 if(distance > 2) {
  // move it with a lerp for a smooth transition over frames
 Vector3.Lerp(character.transform.position, hit1.transform.position, 0.1f);
 } 
 }
Comment
Add comment · 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

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

17 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

Related Questions

Can Someone Help Me With This A.I. Script? 1 Answer

Mysterious behaviour of moving sphere 1 Answer

My character double jumps if he runs, before jumping?? 1 Answer

rigidbody.AddForce affects all clones 1 Answer

Another alternative of rigidbody.AddForce? 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