- Home /
Question by
mastermagpie · Apr 11, 2013 at 04:00 PM ·
javascriptpickupcollisiondetectiondragrigidbody
Stop Object From Ignoring Collisions - Pick Up Rigidbody
So basically, I found this script and have edited it slightly to work for me. It works really well, except for the fact the object that is being picked up glitches out through walls if dragged into them. Is there a way of stopping the object like freezing its position temporarily or improving the collisions so they are stricter? Thanks! (P.S. The script is a little messy at the moment...)
var pointDistance = 3.0;
var pullSpeed = 8.0;
var throwForce = 40.0;
private var mGrabbed : boolean = false;
private var heldObject : Transform;
function Update()
{
if(mGrabbed)
{
var targetPoint = Camera.main.transform.TransformPoint(Vector3.forward * pointDistance);
heldObject.position=Vector3.Lerp(heldObject.position, targetPoint, Time.deltaTime * pullSpeed);
}
if(Input.GetMouseButtonDown(0))
{
if(!mGrabbed)
{
var ray : Ray = camera.ViewportPointToRay (Vector3(0.5,0.5,0));
var hit : RaycastHit;
if (Physics.Raycast (ray, hit))
{
print(hit.transform.name);
if(hit.rigidbody)
{
heldObject = hit.transform;
heldObject.rigidbody.useGravity=false;
mGrabbed = true;
}
}
}
else
{
mGrabbed = false;
heldObject.rigidbody.useGravity=true;
}
}
if(Input.GetMouseButtonUp(0))
{
if(mGrabbed)
{
mGrabbed = false;
heldObject.rigidbody.useGravity=true;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Collision Detection 0 Answers
Weapon Pickup and change 2 Answers
How to pickup and equip an object? 0 Answers
Unity JS - Picking up objects 1 Answer
Movment of character through Java script 0 Answers