I keep hearning that if you use ridigbodies, you should not use transform.position.
Why is that?
I’m not a very talented coder and I feel comfortable using transform.position. But it seems one does wise in using ridigbodies for being able to check collisions.
I don’t want to use much physics, because I’m afraid I’ll dig my own grave.
Think of rigidbodies as an item under control of the physics engine. And if you’re going to play with it you want to toy with the velocity and not it’s actual position, all inside the FixedUpdate() function so it’s in step with the physics engine.
Rigidbodies have nothing to do with collision, that’s the domain of collision hulls/primitives.
I also think you’ll find that physics is fun. Just add some rigidbodies to a few cubes, add some forces and watch them interact. You’ll have a blast.
Don’t get me wrong. I love physics, and just random testing with it is swell as well. But I’m still scared shitless for actually trying to use it in a game.
And as I’ve gathered, they’re kinda related to collision, because of the matrix at the bottom here:
Rigidbody Colliders seems to be the only way to make everything collidable with everything.
First of all, I use transform.position a lot concurrently with physics, and I have yet to encounter any problems or unrealistic behavior. I do, however, understand most of the math involved in what I am doing, so I can accurately calculate the physics myself, if needed. That’s not to say you won’t encounter issues, but I do think people tend to overexaggerate it a bit. You just have to know what you are doing.
Having said that, don’t be afraid of physics in Unity. The whole idea of having a physics engine is that you have less to worry about. You just send one object hurtling towards another. The engine handles the rest. And the fact the you enjoy physics to a degree will only enhance your ability to implement it.
Let me give you an example. I wanted to create a script that would cause bodies to realistically orbit a star. I was initially doing it all manually, using transform.position and doing all the math myself. It worked fine. Then I just tried it by calculating an initial velocity for the bodies and some constant values for the gravity and mass and let the physics engine take over. It worked just fine. Even better, by relying on the physics engine, I was able to create behaviors that I would have had to code for doing it manually. For example, when two of the bodies collided, their velocities changed. When you are orbiting something, and your velocity changes, your orbit changes. Unity handled it just fine, and I didn’t have to add any code at all.
Sometimes you will see a need to handle physics manually using transform.position. Most of the time, however, Unity does a fine job all by itself.
Well you’re somewhat misinterpreting that table. First scroll up to read the definition of a rigidbody collider then go back to the table.
If you notice, it only sets off triggers in all circumstances. This is understandable, as by default it’s necessary for a collision to occur. This is likely because it’s physX handling it and not code unity has rolled on their own. There are however two things you need to understand about triggers.
Unlike regular collisions, triggers do not return detailed collision information about where exactly the event occurred. You simply know that ‘something happened’ and nothing more about it.
When you collide with a trigger, it has no effect on the objects at all. Not exactly what you normally think of in terms of collision. For example if you had your walls use triggers instead of normal colliders and threw a rigidbody against it - it would pass right on through it like it wasn’t even there.
Yeah, sorry if I didn’t make myself clear. What I ment was that I gathered it as the only way to have every object collidable with every other object, while still having the same kind of collider for every object. Having them all as rigidbody colliders, that is.
Well hopefully you understand now that colliders cause collisions, and that the rigidbody is only there to cause the physics engine to ‘do stuff’ when it occurs.
A rigidbody has the same kind of collider as a piece of static geometry. Only difference being the wall doesn’t move when a ball bounces off of it, as it doesn’t have a rigidbody attached.