Trying to create game boundary boxes

Hi,

I’m trying to create a simple boundary box that keeps the player inside the field of play. I did this by using a simple box collider with a bouncy or rubber material. I’m noticing some weird behavior though.

  1. I have to remove the player “is trigger” collider parameter for it to react to the bounding box collider. Why is this?

  2. Once the player does collide, he seems to bounce somewhat uncontrollably off of the object. Sometimes he even goes off screen. This is definitely not what I want. How do I get a more predictable reaction? IE The player collides with the object is gently moved back into the field of play.

Thanks for any help.

  1. How is the player supposed to collide if he’s a trigger? Of course he has to have collision of his own to be able to collide with other colliders

  2. Code it yourself. If you want a soft push back into your playing field you need to code it yourself. Turn on “Is trigger” for your box colliders and then write some code that slowly reverses the player speed once he enters the trigger or something similar.

What kind of game are you making? Seeing as you had the player set as a trigger…

Thanks for getting back to me TwiiK

I’m making a top down shooter. Simple 2D game that’s similar to 19xx and others. etc. I was following the vid tutorials for a simple shooter on Design3. In retrospect, I don’t think the videos instructed me to make the player object a trigger. All colisions (missles and enemies with player) seem to work just fine with out it.

I also set the rotation to Interpolate. That seems to work better.

As to point to, How would I code something like that? Should i do a simple if at this pos push to this one? I’ve tried that, and it is also very disjointed.

Can anyone help? The idea is once the player reached a certain point on the z axis, he’ll be gently pushed back into the play field. So far this isn’t working.

I tried this simple code:

If (transform.position.z > 60)
{
transform.Translate Vector3(0,0,1);
}

Is that copied and pasted directly from your code?

No it’s just an approximation. A theory I guess.

But you said you tried it. So, can you post the actual code that you tried?

I deleted it, but that was pretty close to what I had.

Note that by default, Transform.Translate() applies the translation in local space. How is your object oriented? Is its orientation identity?

It’s oriented by it’s transform. X = -43 Y = 114 z = 4.5

Is that the position? Or the rotation angles?

That’s the position. Rotation angles are 0, 90,0

Ok, well this (pseudo)code:

 transform.Translate Vector3(0,0,1);

Will move the object one unit along its local forward (z) axis. I’m not sure what behavior you’re after exactly; I imagine whatever it is you can get the desired effect using Translate(), but just be aware that the second argument determines whether the translation is applied in local or world space, and is set to ‘local space’ by default.