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 Varls · May 18, 2014 at 10:01 PM · third-personhingejointswinging

Whip swing script JS Indy Jones Style

Working on a 3rd person game and I am trying to implement a whip swing mechanic where the player can swing over obstacles using a whip pretty much like Indiana Jones. There is an object with this script attached to it that the player can swing from. currently ive got as far as using a raycast to see if the player is in range but have run into a brick wall with using a hinge joint to swing the player. If I try to attach the joint to the object it basically looks like the player is using some sort of telekenisis to pick up the object and carry it around. and if I attach the joint to the player then the hinje seems to just push the player away from it. Also currently the joint axis seems to swing around and face what ever direction the character is facing which is controlled by the mouse axis.

Any Help here would be great

Cheers!

pragma strict

 var chController : GameObject;
 var targetPlayer : Transform;
 var otherBody : Rigidbody;
 public var playerInSight : boolean;
 
 private var isWhipping: boolean = false;
 
 function Start () {
 
 chController = GameObject.Find("Player");
 
 }
 
 function Update () {
 
     LineOfSite();
 
 
 
 
     if(Input.GetButton("Fire2") && playerInSight && !isWhipping){
     
     
     
     
     
     
         
         
         otherBody = gameObject.rigidbody;
         gameObject.rigidbody.isKinematic = true;
         chController.AddComponent ("HingeJoint");
         
         chController.hingeJoint.autoConfigureConnectedAnchor = false;
         chController.hingeJoint.connectedBody = otherBody;
         chController.hingeJoint.connectedAnchor = Vector3(0,0,0);
         chController.hingeJoint.axis = -gameObject.transform.up;
         chController.hingeJoint.motor.force = 100;
         chController.hingeJoint.motor.targetVelocity = 90;
         chController.hingeJoint.motor.freeSpin = false;
         chController.hingeJoint.limits.min = -45;
         chController.hingeJoint.limits.max = 45;
         //chController.rigidbody.AddForce (Vector3.forward * 1000);
         
         //chController.transform.collider.isTrigger = true;
 
         isWhipping = true;
 
     }
 }
 
 function LineOfSite(){
 
 var direction : Vector3 = targetPlayer.position - transform.position;
 //var fwd = transform.TransformDirection(Vector3.forward);
 
 var hit : RaycastHit;
           
 // ... and if a raycast towards the player hits something...
     if(Physics.Raycast(transform.position, direction, hit, 10)){      
               
 // ... and if the raycast hits the player...
         if(hit.collider.gameObject.tag == "Player"){
         
 // ... the player is in sight.
             playerInSight = true;
             Debug.DrawRay(transform.position, direction * hit.distance, Color.red);
 
                     
         }else{
                 
             playerInSight = false;
             Debug.DrawRay(transform.position, direction * hit.distance, Color.yellow);
             
                     
         }
                 
     }
 
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

21 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

Related Questions

Swinging movement (WindWaker Like) 3D 0 Answers

2 Hinges on the same object, like a swing. 0 Answers

how connect 2 object 1 Answer

Modifying values on HingeJoints throwing errors when compiling for flash 0 Answers

jungle swing type game ...? 0 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