Sunteți pe pagina 1din 3

Grapple and swing/pull mechanic

I have added some more and have some functionality working but it still does not behave
how I need it to.
Once again, this script is attached to an object (grappling hook) that is parented to a
character models (puppet) hand. it fire from the hand alright but still cant get the movement
of the character right after that. I think the best thing would be to have a hinge/joint that
when the player hits a grapple point, the hinge is enabled and they swing like a pendulum
under the grapple point until a button is pressed and the hinge is disabled. When I have
tried this, I cant seem to get the hinge to disconnect from the player and to attach it to a
different grapple point. Because I am using a character controller, the physics are a real
pain since adding the rigid body and gravity to the puppet causes it to go crazy.
Another idea I had was that the puppet could ping pong between 2 vector3's when on a
grapple point until a button is pressed and they jump off, but am unsure also if this can be
implemented.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.

var
var
var
var

shootForceX=0;
shootForceY=0;
shootForceZ=0;
smooth = 5.0;

var
var
var
var

isShooting
isHooked =
timeShot =
grappled =

= false;
false;
0;
true;

private var GrapplingHitPoint;


public var swingPoint : Vector3;
function Update ()
{
if(Input.GetKeyDown("g") && !isShooting)
{
rigidbody.useGravity = true;
rigidbody.AddForce(shootForceX,shootForceY,shootForceZ);
isShooting = true;
timeShot = Time.time;
}
if(isShooting)
{
if(Time.time > timeShot + 2)
{
isShooting = false;
grappled = false;
retracting = true;

35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.

}
if(!isHooked)
{
returnShooter();
}
if(grappled)
{
IsSwinging();
}
if(retracting)
{
returnShooter();
}
}
}

function IsSwinging()
{
bob = GameObject.Find("Puppet");
//move the puppet to the grapple point
//maybe mathf.pingPong can make the character keep moving back
and forth
60.
bob.transform.position = Vector3.Lerp(bob.transform.position,
swingPoint+ Vector3(6,-1,0), Time.deltaTime * smooth);
61.
62.
}
63.
64.
function returnShooter() //returns the grappling hook to the hand
position
65.
{
66.
yield WaitForSeconds (0.5);
67.
rigidbody.useGravity = false;
68.
rigidbody.isKinematic = false;
69.
rigidbody.velocity = Vector3(0,0,0);
70.
rigidbody.AddForce(0,0,0);
71.
transform.localPosition = Vector3(0.0f, 0.0f, 0.0f);
72.
}
73.
74.
function OnCollisionEnter(collision : Collision)
75.
{
76.
if(collision.gameObject.CompareTag("GrapplePoint"))
77.
{
78.
print("HitGrapple");
79.
isShooting = false;
80.
colliding = true;
81.
rigidbody.isKinematic = true;
82.
grappled = true;
83.
84.
swingPoint.x = collision.transform.position.x;
85.
swingPoint.y = collision.transform.position.y;
86.
swingPoint.z = collision.transform.position.z;
87.
88.
//This gets the character object...

89.
90.
91.
92.
93.
94.
95.
96.

bob = GameObject.Find("Puppet");
//wait before returning the grappling hook to hand position
yield WaitForSeconds (1.5);
returnShooter();
}
}

S-ar putea să vă placă și