Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Prevent Player from pushing a Rigidbody

Discussion in 'Editor & General Support' started by Azaldur, Aug 25, 2012.

  1. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    Hi,

    I got a moving platform with a rigidbody attached. The player can control the platform, so it is important that the platform can collide with other objects. The Player got a characterController Component attached and is moved via simple move(no rigidbody attached to the player). But when I want to walk around with my player on the platform while it is moving, the player pushes the platform away, because the platform "collides" with the player, who's standing on it. How can i prevent the player from doing so, so that the player can still move around on the platform but does not have a physical effect on it? I already tried to parent the player to the platform, but that doesn't make it better.
     
  2. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    Make the platform Kinematic.
     
  3. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    Thanks for your answer :). But then the platform can't collide with other colliders(box, mesh collider..), but it's important that it does collide with everything, except the player.
     
  4. LuringLight

    LuringLight

    Joined:
    Jul 2, 2012
    Posts:
    2
    So, you want the player to react to collision with the platform, but you want the platform to react to other collisions, but not the player?

    I had the same problem when I wanted to use platforms with a spring joint. I scrapped that, and went with animated kinematic platforms instead.

    The only workaround I know that might work for you is to make the platform much heavier than the player.
     
  5. RShackleton

    RShackleton

    Joined:
    Mar 31, 2012
    Posts:
    15
    You should be able to drop the rigidbody altogether.

    As long as the platform has a collider on it and you have made sure the layers the character and the platform are on are set to collide in the matrix (Project Settings > Physics) then I think you should be good to go.
     
  6. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    But without a rigidbody the platform cannot collide with static colliders, but it is supposed to do. More specifically, I make a game where a player controls a ship. The ship should be able to collide with static colliders like rocks oder islands and the player can walk around on the ship while it is still moving. It is a multiplayer game, so while one player controls the ship, the others can walk around on it. I can't imagine that there isn't a way to make this work.
    Yeah, thats right :).
     
    Last edited: Aug 26, 2012
  7. Swearsoft

    Swearsoft

    Joined:
    Mar 19, 2009
    Posts:
    1,632
    I think you need two objects to work as the ship, the hull and the platform let's say. One is a rigidbody (hull), the other is a collider (deck), the deck is parented to the hull.

    or layers.
     
    Last edited: Aug 26, 2012
  8. LuringLight

    LuringLight

    Joined:
    Jul 2, 2012
    Posts:
    2
    I just found a better workaround for this. You'll need to use three different collision layers and set them up properly in the collision matrix.

    To set it up, you need to make it so the player can't collide with the layer the platform (ship) is in. Then make a second object that contains only a collider and rigidbody that are the exact same as the platform, except make this one kinematic. Make it so this layer can only collide with the player. On the new platform, attach this script and set rigidBodyToMimic on the inspector to the original platform.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MimicRigidbody : MonoBehaviour {
    6.     public Rigidbody rigidBodyToMimic;
    7.  
    8.     void FixedUpdate()
    9.     {
    10.         rigidbody.MovePosition(rigidBodyToMimic.position);
    11.         rigidbody.MoveRotation(rigidBodyToMimic.rotation);
    12.     }
    13. }
    14.  
    15.  
    edit: I think you might only need 2 layers, one for the the player and invisible platform, one for the original platform. Anyway, the premise is the same. Hopefully, this works for you.
     
    Last edited: Aug 26, 2012
  9. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    Koyima and LuringLight, thank you very much :). I'm going to try it tomorrow and let you know if it worked or not, but it sounds very good.
     
    Last edited: Aug 26, 2012
  10. Azaldur

    Azaldur

    Joined:
    Jul 10, 2011
    Posts:
    52
    Hi,
    sorry for the late reply, I didn't had the time to do much on the project last week. But I tried the suggestions yesterday and everything works fine :). So if someone got a similiar problem, what LuringLight and koyima posted is propably the solution for you.
     
  11. KuPAfoo

    KuPAfoo

    Joined:
    Aug 24, 2013
    Posts:
    17
    My model is jumping when "OnCollisionEnter" isn't active >.>