- Home /
How to get my child objects to follow the parent? Also, not sure if this is working.
I know this sounds routine but it really isn't. I have 3 objects: a player, a hinge and a weapon. When I hold a or d it charges a power bar which then applies torque to the hinge, which in turn rotates the weapon. When the weapon hits the ground it is supposed to apply a large amount of force to the player and the hinge and weapon should stay with it. I actually have 3 problems: 1. When I don't lock the rotation on the weapon it simply breaks and the player doesn't move 2. When I do lock the rotation on the weapon then it goes into the ground and then the player goes flying off without the weapon or the hinge ( The hinge is a child of the player and the weapon is a child of the hinge. And I have tried using lerp.) 3. Because of problem 2 I don't know if the player is flying away due to my script or due to Unity's physics
This is the code used to calculate my force if that is any help.
public float angle = 0;
public GameObject Player;
public GameObject PlayerMain;
public PowerBar PowerBarInstance;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void OnCollisionEnter(Collision col){
if(col.gameObject.name == "Weapon"){
PowerBarInstance.Force = (PowerBarInstance.OriginalRotation - Player.transform.eulerAngles.y) * PowerBarInstance.thePower;
PlayerMain.rigidbody.AddForce(-Player.transform.forward * PowerBarInstance.Force * 10000);
}
Sorry for asking so much, but I've been messing with this for weeks and still can't fix it. Thanks in advance to anyone who helps.
Your answer
Follow this Question
Related Questions
Set Velocity at relative position. 2 Answers
Get result (force & torque) of AddForceAtPosition? 2 Answers
Predicting land position with drag applied 0 Answers
How to make a dynamic bow shot and the arrow to curve and turn correctly when shot? 0 Answers
Calculating required force for pushing a body to a desired position at once 0 Answers