- Home /
Making a cube fall without rigidbody
I am making a 3d puzzle game with blocks. Right now for gravity a I use rigidbody. The problem with this is that cubes push down on each other and look uneven. I have tried a seperate fall script but I don't know how to do the collisions to fall down to the closest cube below it and stop? I don't need a whole script, just suggestions.
What do you mean by "look uneven"? No real time physics can be fully accurate, so keep that in $$anonymous$$d :)
If you pick up a cube and place it again, it sinks past the other cubes a little bit. Here is a picture:
I am picking it up and dropping it by using physics.raycast to deter$$anonymous$$e the cube clicked on.
I asked how you pick it up, not how you deter$$anonymous$$e which one to pick up :|
The answer you have is a good one, you should probably accept it :)
Answer by Grim_Darknight · Jul 25, 2013 at 01:45 AM
For your cubes if all they do is move verticaly you can constrain their movement in the X and Z axis on the rigidbody component. You can also lock the rotation which will keep them oriented properly.
@jg2115 Even though the question was "$$anonymous$$aking a cube fall without rigidbody", this is a good solution. You weren't wanting to use a rigidbody simply because of the shaking and whatnot, follow this guy's advice and have a look at Rigidbody.constraints. This is an easier solution than moving the cubes manually with code, and using raycast to detect landing.
Rigidbodies are pretty useful. Combine that with raycasting and some educated guesses and you could turn gravity on/off (or velocity) and relocate the object to the correct height as soon as it gets close (to snap it in). After it's locked in, disable the rigidbody until you need it again.
Without knowing more I'd think the rigidbody is still the answer here and that you should be asking how to better utilize it if you still need help getting what you want.
You could also use raycast to detect if a cube is sitting on another cube, and lock the position, then make the rigidbody kinematic so it will stay in place. Then when you click on it, make it non kinematic again so it can be dragged around. It you're interested in this idea I'd be happy to do a basic tutorial for you.
Your answer
Follow this Question
Related Questions
Object goes through wall. 0 Answers
How to get movable/pushable cubes right? 0 Answers
Cube starts shaking when placed on a giant sphere 1 Answer