#pragma strict
var firePit : GameObject;
var catchRange = 30.0;
var holdDistance = 4.0;
var minForce = 1000;
var maxForce = 10000;
var forceChargePerSec = 3000;
var layerMask : LayerMask = -1;
enum GravityGunState { Free, Catch, Occupied, Charge, Release};
private var gravityGunState : GravityGunState = 0;
private var rigid : Rigidbody = null;
private var currentForce = minForce;
function FixedUpdate()
{
if(gravityGunState == GravityGunState.Free)
{
if(Input.GetKey(KeyCode.LeftControl))
{
var hit : RaycastHit;
if(Physics.Raycast(transform.position, transform.forward, hit, catchRange, layerMask))
{
if(hit.rigidbody)
{
rigid = hit.rigidbody;
gravityGunState = GravityGunState.Catch;
}
}
}
}
else if(gravityGunState == GravityGunState.Catch)
{
rigid.MovePosition(transform.position + transform.forward * holdDistance);
if(!Input.GetKey(KeyCode.LeftControl))
gravityGunState = GravityGunState.Occupied;
}
else if(gravityGunState == GravityGunState.Occupied)
{
rigid.MovePosition(transform.position + transform.forward * holdDistance);
if(Input.GetKey(KeyCode.LeftControl))
gravityGunState = GravityGunState.Charge;
}
else if(gravityGunState == GravityGunState.Charge)
{
rigid.MovePosition(transform.position + transform.forward * holdDistance);
if(currentForce < maxForce) {
currentForce += forceChargePerSec * Time.deltaTime;
}
else
{
currentForce = maxForce;
}
if(!Input.GetKey(KeyCode.LeftControl))
gravityGunState = GravityGunState.Release;
}
else if(gravityGunState == GravityGunState.Release)
{
rigid.AddForce(transform.forward * currentForce);
currentForce = minForce;
gravityGunState = GravityGunState.Free;
}
}
@script ExecuteInEditMode()
I’ve been tinkering with this code trying to make a certain item in game not get picked up but still have a rigidbody attached to it. Because I have a script that allows me to craft a Firepit. I want the firepit to be spawned but not be able to get picked up by the player I want it to just fall to the ground where they’re standing. I know I shouldn’t be here asking for people to do my code for me so if you have any suggestions about where I should start at least that would be great.