- Home /
Question by
epic1legend · Mar 20, 2014 at 03:27 AM ·
collisionbeginnerparentchildoncollisionstay
Child object not moving with parent
I am trying to make my player move with an object if it is in its collider and the "e" button is being held down. The player is becoming a child of the gameobject and is moving with gameobject, but gravity is still being applyed to him and the can still move him, I don't want this.
#pragma strict
var player : GameObject;
function OnTriggerStay (other : Collider) {
if(Input.GetKey("e") && other.tag == "Player")
{
other.transform.parent = gameObject.transform;
player.GetComponent(CharacterMotor).enabled = false;
Debug.Log("attached"); //testing to see if trigger works
}else{
transform.parent = null; //unparent object if animation isnt playing
}
}
Comment
Use a FixedJoint to connect them rather than a parent/child relationship.