Can you help me sort out my script and collision?


I’ve been at Google, Unity Forums, and documentation for awhile now but can’t see to fix the problems that I’m having. I’m trying to make a script that when the player clicks an object (In this case a flashlight) the object lifts in the air, comes to the player, and rests on the screen in front of the player (Where the flashlight would normally be held out for use in game as if it were auto equipped.)

The biggest problem that I’m facing is that the flashlight gets stuck on walls when I’m walking around.

Here’s the set up that I’m using.

  1. Flashlight mesh with box collider. This collider has a physics material with 0 friction on everything. This is not set to trigger so it can collide with other colliders.

  2. I have an empty game object resting beside the player where I want the flashlight to go. This collider is set to trigger.

  3. My walls also have box colliders with physics materials with fictions of 0.

Here’s the script attached to the flashlight.

#pragma strict

var speed = 4.0;
var FlashLightHolder:GameObject;
var PickUpFlashlight = false;
private var increment:float;
private var rotation:Quaternion;;
private var FlashLightInPlace = false;

function OnMouseDown(){

	PickUpFlashlight = true;
	Debug.Log("PickUpFlashlight = true;");


// Create a function that will parent the flashlight to the falshlight holder
// when the flashlight enters the flashlight holder.

function OnTriggerEnter(MyTrigger: Collider){

		Debug.Log("collision detected between flashlight and flashlight holder.");
	if ( == "FlashLightHolder"){
		Debug.Log("Collision If Statement Fired.");
		transform.parent = FlashLightHolder.transform;
		FlashLightInPlace = true;


function Start () {


function Update () {

 if(increment <=1 && PickUpFlashlight == true)
increment += speed/200; // This will affect the speed object travels at.
// position of flashlight = outcome of function below. The first value passed is the position
// of the flashlight (script object), the second arguement is the position of object b (game object, 
// and the third arguement is the speed at which the moving object will travel. 
transform.position = Vector3.Lerp(transform.position, FlashLightHolder.transform.position, increment);
//Add this block only if you want the rotation also be transitioned to objectB's rotation.

/* Declare a variable of vector  (Representation of 3D vectors and points.) This vector variable
equals position of player or game object - position of flashlight (script object)

var direction:Vector3 = FlashLightHolder.transform.position - transform.position;

// Set the value of rotation Quaternian to 

rotation = Quaternion.LookRotation(direction);

transform.rotation = Quaternion.Slerp(transform.rotation, rotation, increment);
PickUpFlashlight = false;


A second problem that I’m having is when the flashlight gets to the collider flashlight holder that I have parented to the player it kinda snaps into place weird… Not horrible, but not smooth enough…

Is there anyone that can please help me sort of my script and collision problems. I just can’t seem to find the answers…

Thanks a million,

I believe the normal solution people use is just disabling the collider on the flashlight / weapon when the player has picked it up.