- Home /
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);
}
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613145339im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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