Search Unity

How to make my border solid?

Discussion in 'Physics' started by Kinkladze11, Apr 22, 2015.

  1. Kinkladze11

    Kinkladze11

    Joined:
    Feb 25, 2015
    Posts:
    36
    Hi Guys,

    Am a relative newbie here so hope my question isn't too daft...........

    I am trying to clamp my character within a standard screen border that I created.

    So far I've added 4 different edge colliders to both horizontal and vertical parts of the border and I've applied a rigid body component. In addition, I've tried to hugely increase the borders rigid body mass thinking this would make it too heavy to move.

    However, my character can still pass through it (although it does move the border slightly so there is obviously some collision going on).

    Any help would be greatly appreciated.

    Thanks in advance as always :)
     
  2. Kinkladze11

    Kinkladze11

    Joined:
    Feb 25, 2015
    Posts:
    36
    Hate to be the first one to reply to my own thread......(how embarrassing....:)

    Have nearly solved this (more through luck than judgement) :-

    I now have it in a state whereby if I set the game characters rigid body gravity setting to above 0.......it falls and hits the lower horizontal part of the border and sits there, hence the border appears to be solid as intended.

    However, if I set the gravity back to 0 and use the coded mouse control to move the character, the character simply passes right through.
     
  3. BitBanga

    BitBanga

    Joined:
    Apr 20, 2015
    Posts:
    5
    Hi,
    as i understood, you are using rigidbodies for the borders. I don't think thats necessary. Rigidbodies are usually used to get physically correct Behavior, like for example a rolling rock. Your borders should just have a collider to get solid.
     
  4. Kinkladze11

    Kinkladze11

    Joined:
    Feb 25, 2015
    Posts:
    36
    Thanks for the reply.

    If I remove the rigid body there is no effect.

    My understanding is that the collider does just that, i.e. detects collision between 2 or more objects, it doesn't actually action anything. Even though my border isn't doing much other than be totally solid, I still thought it should require some physics based properties that the rigid body gives it.

    However, it's still not working so I guess I must be wrong...........
     
  5. Kinkladze11

    Kinkladze11

    Joined:
    Feb 25, 2015
    Posts:
    36
    Finally solved it with the following code (guess there's a much more efficient way to do it but hey....I'm new to this :)

    void Update(){

    if (transform.position.x <= -13.8) {

    Vector3 limitScreenPos = new Vector3 (-13.8f, transform.position.y, screenPoint.z);
    transform.position = limitScreenPos;

    }

    if (transform.position.x >= 10.1) {

    Vector3 limitScreenPos = new Vector3 (10.1f, transform.position.y, screenPoint.z);
    transform.position = limitScreenPos;

    }

    if (transform.position.y >= 5.9) {

    Vector3 limitScreenPos = new Vector3 (transform.position.x, 5.9f, screenPoint.z);
    transform.position = limitScreenPos;

    }

    if (transform.position.y <= -6.4) {

    Vector3 limitScreenPos = new Vector3 (transform.position.x, -6.4f, screenPoint.z);
    transform.position = limitScreenPos;

    }