0
\$\begingroup\$

I know this is an old question and it has been answered for a lot of people. Unfortunately none of the solutions apply to the problem I seem to have with rigidbodies.

I have a moving AI character and the playermodel. When the AI gets to close the player just bumps on top of it. If I unattach the rigidbody from the moving AI this does not seem to be a problem. My player is controlled by a charactercontroller and the rigidbody is set to "Is Kinematic".

Of course, when none of the agents has a rigidbody my entire combat mechanic falls apart. Does anyone have any idea on how to solve this?

For clarity, here is a short demonstration of the bug: Bump

And the code in question:

void FixedUpdate ()
{
    if (!controller.isGrounded) 
    {
        movement.y -= gravity * Time.deltaTime;
    }
    controller.Move (movement * Time.deltaTime);
}

void CalcMovement (float h, float v)
{
    movement = new Vector3 ();

    if (v != 0 || h != 0) {
        movement = v * forward + h * right;
        movementDirection = movement.normalized;
    }
}
\$\endgroup\$
6
  • \$\begingroup\$ Are you sure your player is Kinematic? and still bumping? BTW, why you player is Is Kinematic enabled? I'm sure if it is not, then at least AI can push you little bit. And can you explain what are you doing OnCollisionEnter? \$\endgroup\$ Commented Dec 25, 2015 at 16:19
  • \$\begingroup\$ @HamzaHasan The player does not have the rigidbody, that is Kinematic, it's the other character. Yes I'm sure it is enabled. When I searched on the web, this was always the solution that seemed to work... not for me... I'm using OnCollisionenter with the weapons, and have them deal damage when they hit a specified target. \$\endgroup\$
    – Biggzlar
    Commented Dec 25, 2015 at 16:39
  • \$\begingroup\$ I hope you are using Capsule colliders. Right? \$\endgroup\$ Commented Dec 25, 2015 at 16:42
  • \$\begingroup\$ Yes, all the colliders are capsule colliders. For the weapons as well as the characters. \$\endgroup\$
    – Biggzlar
    Commented Dec 25, 2015 at 17:20
  • \$\begingroup\$ Have you tried to 'play' with Slope Limit (Limits the collider to only climb slopes that are less steep (in degrees) than the indicated value.) and Step Offset of char controller? docs.unity3d.com/Manual/class-CharacterController.html \$\endgroup\$ Commented Dec 28, 2015 at 8:35

2 Answers 2

1
\$\begingroup\$

This is not quite what I hoped for, but it did solve the problem of the bouncing. I replaced the rigidBody and the capsuleCollider with a CharacterController. I don't know if this is an efficient way of avoiding rigidBodies and still having collision and trigger detection, but it's a working way.

\$\endgroup\$
0
\$\begingroup\$

You can have a try to remove the rigid body from your player. A Character Controller component contains rigid body and Collider

\$\endgroup\$
5
  • \$\begingroup\$ As mentioned, only the other character has a rigidbody. \$\endgroup\$
    – Biggzlar
    Commented Dec 28, 2015 at 8:22
  • \$\begingroup\$ In the gif you upload ,your player can be affected by gravity.But if the player do not attached the rigid body, he wouldn't affected by gravity anymore~And what is the other character?your AI robot? \$\endgroup\$
    – xh.Bao
    Commented Dec 28, 2015 at 9:40
  • \$\begingroup\$ Yes, that is true. To apply gravity I substract a vector from the movement vector that I use to .Move() the player. And yes, the textureless model is a very basic AI bot. It basically just tries to get to the playerposition. \$\endgroup\$
    – Biggzlar
    Commented Dec 28, 2015 at 10:30
  • \$\begingroup\$ And can you show your code? \$\endgroup\$
    – xh.Bao
    Commented Dec 28, 2015 at 14:38
  • \$\begingroup\$ I added the relevant code to the original question. \$\endgroup\$
    – Biggzlar
    Commented Dec 29, 2015 at 13:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .