So I started work on an ECS physics character controller, and I need to take the local space input and turn it into global space directions. I was able to port most things from my original physics character controller just fine. But I need this function, does anyone have an equivalent given through Unity? Or perhaps one I can make myself?
Also, Mathf.Clamp() should be threadsafe. I don’t see why it shouldn’t be, (Mathf.Clamp just returns in a Job system without throwing any errors) it’s a static function.
I’m not sure what data you are starting out with, but assuming you have a LocalToWorld component with a float4x4 matrix describing the local-to-world transformation, you can use the rotate function that will behave like TransformDirection.
In general it might be helpful to use the functions provided in the mathematics package since they are burst-compatible and can be used from whatever thread you please This one also includes a clamping function that you can use.
Thanks, for some reason float4x4.rotate wouldn’t show up. So I just copied the function off of Github. Also, the naming conventions for the math library are really wonky. Why is everything lowercase in this library but not others?
Now I just need a way where I can lock the rotation of my physics controller. I’ve tried setting the rotation through RotationEulerXYZ, but that doesn’t quite work.
The idea behind the naming convention is to make it closer to how you’d write math code in a shading language. I find it quite convenient, but I can definitely see how it sticks out a bit in the .NET/C# ecosystem.
I think I’m lacking context to competently answer this. I haven’t looked too deeply into the new DOTS physics package yet, but I assume that you can override whatever it outputs if you make sure that you actually get to update the rotation after it and before the transform system compues the local-to-world matrix. Maybe it’s an ordering issue? I’d have to look into how that package interacts with the transform systems.
My best guess is that it has something to do with the fact that ECS physics uses the Job System. Currently, I’m just running everything on the main thread (without a Job). So I’d assume my rotation gets overridden by the Physics System. I’ve tried to make a hack where I use velocity to lock the rotation but that hasn’t worked much at all yet.
We need physics constraints like on normal Rigidbodies. Would make it significantly easier. That or allow us to change the rotation/position in the Physics System through some component or something.
I did some more screwing around and found out that I can control the rotation manually, however, it will only work through a job. Doing it on the main thread means my rotation changes are ignored.
Put simply, we just need a way to control rotation (and most likely position as well) through the Physics System. So the Physics System will actually play nice with me changing rotation and position manually. Also having the ability to apply constraints on a physics body would be a clean solution as well.