Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How to make a character speed up when it collides with a plane?

Discussion in 'Physics' started by JohnFromMath, Dec 18, 2014.

  1. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    I'm using the plane as a speed-boosting pad. I'm sure it's something in the scripts, but how can I use a collision with a certain other object (in this case, a specific plane) to cause the character's speed to increase?
     
  2. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    It looks like it's something in the collision detection. I literally can't get the character to recognize collisions at all, with anything. I've placed collision-detection code of various kinds, like this (http://unity3d.com/learn/tutorials/modules/beginner/physics/on-collision-enter) in various places in the ThirdPersonController script and a variety of places with a Debug.Log("hi"); to tell me if it's working, and it never is. What could I be doing wrong?
     
  3. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    I've even tried having the boost pad use CollisionFlags, which work fine with the character herself, but nope, it doesn't recognize them. Why, world?!
     
  4. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    AND the pad recognizes actual collisions when they're happening with everything EXCEPT the character. I must've run over the dog of someone up there.
     
  5. TiG

    TiG

    Joined:
    Feb 28, 2011
    Posts:
    308
    For the collision detection to work, your gameobject must have a rigidbody. After you get a OnColisionEnter you can use collision.relativeVelocity to get the impact velocity. Then you can modify your rigidbodies velocity to increase this.
     
  6. JohnFromMath

    JohnFromMath

    Joined:
    Dec 18, 2014
    Posts:
    22
    FINALLY solved it!

    Thanks, TiG, but the issue was recognizing the collision - both objects already had RigidBodies; I got it to work by modifying the "OnControllerColliderHit" function in the character's ThirdPersonController (js) script and using the code (if hit.gameObject.name == "Boost Pad").

    Oh, yeah, this is so cash! Time to get to making grind rails now!