Search Unity

[SOLVED] I'm trying to have one character ride on another, and move around

Discussion in 'Physics' started by KvaGram, Feb 27, 2016.

  1. KvaGram

    KvaGram

    Joined:
    Aug 22, 2015
    Posts:
    2
    So I am stuck with some weird physics behavior.
    I am working on a new core feature for my game, but the physics don't seem to agree with my attempts.

    I explain everything in this video.


    I have attached the relevant scripts for the car and testrider.
    Please tell if you need more information to help me.
     

    Attached Files:

  2. KvaGram

    KvaGram

    Joined:
    Aug 22, 2015
    Posts:
    2
    Problem solved.
    There were two separate bugs causing the issues.

    1: Having one active rigidbody riding another, couses wild behavior.
    This was solved by having the rider have its rigidbody disabled this way:
    Code (CSharp):
    1.             if(IsRiding)
    2.             {
    3.                 rb.isKinematic = true;
    4.                 rb.detectCollisions = false;
    5.             }
    6.             else
    7.             {
    8.                 rb.isKinematic = false;
    9.                 rb.detectCollisions = true;
    10.             }
    2: My code for having the body of the characters turn in the direction it is supposed to be going:
    Code (CSharp):
    1.             if(move.magnitude > 0.3f)
    2.                 body.transform.rotation = orientation;
    3.             rb.velocity = orientation*Vector3.forward * move.y + orientation*Vector3.right * move.x * 0.8f + new Vector3(0, rb.velocity.y, 0);
    Accidentally rotated in more angles than one as intended (Y-axis).
    And so I managed to get that fixed by removing the other angles.
    Code (CSharp):
    1. orientation.eulerAngles = new Vector3(0, orientation.eulerAngles.y, 0);
    This second issue has actually existed for some time, but was never discovered prior to making this basic AI. As the orientation never had have other angles than Y. But as I now was aiming towards a target not perfectly level with the character, now I know.

    Well, although nobody came to help, I hope this is of some help to others.