I have looked through the reference, tutorials, forums, and ask Unity, but can’t find this simple question asked. It’s difficult to search google for this as everything BUT the question pops up, as others seem to use prefabs.
I have Box collidors on my objects and player, and a rigidbody on my player.
Now… I am trying to find the code to block movement so the player can’t walk through objects with box collidors, can’t walk through walls, can’t walk through objects, etc.
Yet I can’t find anything here. I am afraid of messing with movement, as my mind comes up with only resolutions which would cause my player to freeze and have his speed set to 0, becoming paralyzed from the neck down.
Simple question, but certainly not something easily found in the reference, forum, or ask Unity website. Ugh!
for a character generally capsule setup work best shape wise , plus mesh collider in animated character wont work at all , so this is somthing to keep in mind
otherwise the character controller provided by unity offer a nice and smooth blocking collisions generally.
but as InvaderStudio said basically get collision to take effect in unity doesn’t require code right away, adn should work out of teh box if you setup your stuff correctly in the scene
I attached rigidbodies to everything and made sure the Z layer is the same, made sure to uncheck isKinematic (and checked, I tried every combination lol)
My game is a 2D game, so I locked everything except X and Y position, but I still have a problem. Whenever it collides, it “bounces” off of the object and starts flying backwards to infinity.
Honestly, I just want a simple block movement, can’t go through walls, type of thing. Not a “You collided, so now you will go backwards unto infinity in space like Bender in Futurama.”
in that case you can use just trigger and isKinematic , and from the event you get from your wall trigger let say , just define the position which should stay the player.
or something in this idea, after this come on how complex your wall are setup , if you are using true 3d objects but in a 2d fashion view then try using character controller eventually for your main character, it generally do the work ( may be just a bit expansive perf wise , but for a unique entity in game this still stay quite reasonnable ).
if you are using sprite then either try your way around trigger or otherwise you will need to come with a more “custom” solution.
I would also like to find a solution to this. I’m using a Character Controller with my main character, and I’ve used a the same for an object and it passes right through it. If I use a box collidor, it kicks the box around (it collides and works, but the box isnt meant to move, but to PREVENT the character from moving).
I have rigibodies on everything, assuming it couldn’t hurt.
You only need one player with any collider and a rigid body. lock the movement. You only need one cube with collider, not rigidbody. You don’t need any other parameters or anything at all.
You are probably over-coding it and messing it up.
i’m having some issues getting this working. I’ve got 2 objects (a simple cube w/a box collider on it + rigid body) and a blocker which is a game object with a large box collider on it. No matter what settings i change the cube will go right through the collider object, no problem. I’m trying to create a blocker system for a mini game so the user can not push the pieces beyond a point and so far nothing has worked for me.