Hi again,
another question i have:
i try to connect a object to my car.
i modified the sticky grenade object so i could give my car a car attached. but it doesn´t work
the other car always connects to the ground, but it should not do this.
so how can i solve this?
the sticky grenade script should only work with a key hitted and only with my car.
i do not now where i can put the two ifs in
first : only when key “x” is pressed
and second:
only if the player car comes around…
thanks
/// This script requires that a rigdibody is attached to the same game object
private var localAttachmentPoint = Vector3.zero;
private var attachedTransform : Transform;
private var isAttached = false;
//Enable only when we have a collision
function Awake ()
{
enabled = false;
}
function OnCollisionEnter ( col : Collision )
{
if (isAttached)
return;
isAttached = true;
// When we hit a rigidbody we attach to it with a fixed joint
// this gives extra realism eg. the grenade’s mass will now pull down the attached to rigidbody
if (col.rigidbody.CompareTag (“Player”))
{
var joint = gameObject.AddComponent(“HingeJoint”);
joint.connectedBody = col.rigidbody;
hingeJoint.limits.min = 0;
hingeJoint.limits.minBounce = 0;
hingeJoint.limits.max = 90;
hingeJoint.limits.maxBounce = 0;
}
// When we hit a normal collider we just follow the transform around!
else
{
// Store local attachment point and transform we stick to
attachedTransform = col.transform;
localAttachmentPoint = attachedTransform.InverseTransformPoint(transform.position);
// The grenade’s position is now driven by the script instead of physics
rigidbody.isKinematic = true;
enabled = true;
}
}
//function Update1 () {
// if (Input.GetKey (“space”)) {
// isAttached = false;
// }
//}
function Update ()
{
// Update position to follow the object we stick to
if (attachedTransform)
{
transform.position = attachedTransform.TransformPoint(localAttachmentPoint);
}
else
{
// The attached transform was destroyed. Let go and enable physics control
rigidbody.isKinematic = false;
enabled = false;
}
}