I’m reeeeally new to DOTS and ECS…
I’m trying to use the new Unity Physics to move a simple cube.
My questions are:
Q1: To move an object with Unity Physics, it needs a Rigidbody. Is this UnityEngine.Rigidbody or Unity.Physics.Rigidbody?
Q2: To maintain my object on the ground, it needs a Collider (Box in this case). Why doesn’t it move with the player when I use Unity Physics to move the the player?
Q3: Are there any types of collider that support the new Unity Physics? Because in the earlier versions of ECS exists something called Physics Shape, with is used with Physics Body (current Unity.Physics.Rigidbody I guess)
My personal answers:
A1: It is a Unity.Physics.Rigidbody, because it works with PhysicsVelocity.ApplyLinearImpulse().
A2: Its related to the difference between GameObject and Entity. When I add a Collider from the component selector in the inspector panel, it basically adds a UnityEngine.Collider (in my case it adds a UnityEngine.BoxCollider).
A3: No, there aren’t. Ok… Just resolve Q2 and try again with Q3!
Q1: You can use both, but there is something important you must understand : the baking system. During the editor time, you author your data using classic gameobjects that you put into subscenes, which then baked into optimized data to use at runtime in the ecs workflow. So if your question is how can i create a rigidbody to use in ecs, the answer is either use the classic rigidbody and collider component from gameobject part of unity, or use the custom ones provided in the samples of the physics package (check the package manager). The result should be the same (don’t forget to put them into subscenes). But do note that the data is converted to component, and the runtime component for moving physics object in systems is the PhysicsBody.
Q2 : I think from what you describe here that your character controller is a classic gameobject physics character, powered by PhysX (the motor behind unity gameObject part). This is then indeed a incompatibility between gameobject and ecs : their physics don’t interact. If you want things that interact, your character controller must be a ecs one, and in your case you should check the excellent package unity provides : com.unity.charactercontroller.
Q3 : All the shapes components (box collider, sphere, mesh…) unity gameobject support should be supported in ecs and converted to ecs when put in subscenes. If you want more control over your colliders, i recommend installing the custom authoring components in the samples.
And last thing you can check, if you get really invested in ecs, are all the gdc and unite talks on youtube (don’t start with that, they use old api, it is just if you want to understand more deeply the mindset behind the creation of those packages, once you have mastered them)
By the way, there is a physics subforum : Unity Engine - Unity Discussions (for future physic questions you might have, I believe your question would have been at a better place in this subforum).
I prefer to use rigidbody, because I think it is really more flexible and customizable. Anyway, Character Controller is a really good choice as a starting point.
My problem in Q2 is related to the collider wich I add in the inspector: the collider, as you said, doesn’t interact with Unity Physics, so it remain in the spawning position. So I have to find a way to move both player and collider, I guess…
Surely I missed something (the samples you are talking about, for example) while installing the package.
About Q2, something that is crossing my mind with your message is that you don’t mention any rigidbody. If you don’t add a rigidbody (or if you set it to kinematic) to the collider, it will be considered static and will interact with the player (push him away) but will remain in the spawning position. This would fit your description. But as this is the same in gameObjects, you might very well have thought about that, and in that case, I’ll let you find the problem with the samples. Another thing that struck my mind is the idea that layers might be setup for your collider and player not to interact. Anyway, I’ll stop speculating on what the problem is, and let you fix it.
Enjoy the samples, there is quite a lot to go through, .
Hmm…
This “debug session” grows in me many many questions
How many colliders are there? Why my Cinemachine camera follows the collider on the left and not the right one?
As you can see, now I’m using Physics Shape and Physics Body.
Is this related to the fact that Cinemachine could be not updated for ECS?
EDIT: I removed the Cinemachine camera and made a script to follow player (entity). I discovered that the main camera isn’t considered an entity… What? So it hasn’t Local Transform.
The samples of Character Controller contains a workaround for camera. Basically, it spawns an entity, does camera algorithm in the ECS, and applies the transform back to Camera game object.
The system from the character controller is what I use most of the time, but as you mentioned Cinemachine, I can point you to a tertle package that did a cinemachine wrapper to entity : Tim (tertle) / com.bovinelabs.camera · GitLab. If you really want can’t wait Unity to release its own version of the ecs cinemachine (which is planned), and that the character controller workaround is not enough for you to build your project in the meantime, you can try this package.