#How do I move a Physics Entity like a GameObject with a Rigidbody?

1 messages · Page 1 of 1 (latest)

stark totem
#

So far I've been moving all of my monsters towards the middle of my level using transform.Position movement every tick.
I want to change this so that the monsters are moved by Physics, as I would like monsters to push each other out of the way and collide in the scene with objects, each other, structures and the player.

In a GameObject workflow I would simply add a Collider and a Rigidbody and then go into the Rigidbody and specify that I want the body to not rotate in the X, Y and Z axis as well as not moving in the Y axis. What this should do is provide me with a GameObject that can move along the X and Z axis using physics and with the constraints that it cannot rotate nor move in the Y direction.

However, when I convert my monsters with a Capsule Collider and Rigidbody, setup as mentioned above, it doesn't quite work as expected. The monsters do become rigidbodies but they simply fall over immediately when the world spawns in. They are not trying to move towards the center either. So I clearly did something wrong here and I would like help to course correct. See code and images below 🙂

#

Here you can see that the capsules just kind of fall over

#

Here is the code I try to use to make them move:

[BurstCompile]
public partial struct MonsterCapsuleMovementJob : IJobEntity
{
    public float DeltaTime;

    readonly void Execute(ref MonsterCapsule monster, ref PhysicsVelocity velocity)
    {
        velocity.Linear = monster.MoveDirection * monster.Speed * DeltaTime;
    }
}
#

And lastly this is the prefab

#

How do I move a Physics Entity like a GameObject with a Rigidbody?

sonic scaffold
#

this didn't work for a long time and i hadn't checked recently, but hmm looking at source this kind of looks like it should be working now

stark totem
#

Ah

sonic scaffold
#
                automaticInertiaTensor = authoring.automaticInertiaTensor,
                inertiaTensor = authoring.inertiaTensor,
                inertiaTensorRotation = authoring.inertiaTensorRotation```
#

it seems to read the tensor now

stark totem
#

I'm not doing anything to author the physics component

#

I assume that Unity converts that automatically

sonic scaffold
#

this is from the RigidBody baker

stark totem
#

Is there anything else I might need to do when I spawn the monster in to retain the physics constraints?

sonic scaffold
#

oh

#

try untick automatic tensor

stark totem
#

That didn't seem to change the behaviour at least.

sonic scaffold
#

did it expose any properties?

stark totem
#

It did, yes.

sonic scaffold
#

hmm they're set to 0

#

which is what they should be for freeze rotation

stark totem
#

So is it possible it's a bug that hasn't been fixed?

sonic scaffold
#

can you set them to infinite

#

maybe dots physics doesn't have the same behaviour of physx

#

basically 0 isn't valid, and physx treats 0 as infinite

stark totem
#

The rotation values seem to stop at 90, 180, 180

#

Or, well

#

It's weird

#

When I start editing those fields, the others start changing too

sonic scaffold
#

yeah i just noticed

stark totem
#

Okay, slight development. I can see that the speed I had initially was simply too low to have them move towards their target.

#

But the not-locked rotation is still an issue

sonic scaffold
#

seems to work fine with the alternative physics body / physics shape

#

if you go into advanced, override and set Infinity

#

unfortunately i don't have time atm to figure out what's up with this rigidbody though

stark totem
#

Okay. If this works for now, then that's likely good enough and I appreciate your time. Perhaps we can pick this back up again when you do have time, if you would be so kind 🙏

sonic scaffold
#

i personally still stick with the old components as i prefer them

#

so i have not played around with how baking works on rigidbody/colliders

stark totem
#

How do I get that advanced screen?

sonic scaffold
#

if you go to your package manager

#

find physics

#

look at its samples

#

you can import these 'old' style authoring

#

PhysicsShape + PhysicsBody

#

instead of Collider + RigidBody

#

has a bunch of extra options

stark totem
#

Ah okay.

#

Yeah I read about that but I was so confused on where to find those

#

It would be nice to not have to rely on this when that isn't the intended workflow. Although if I have to, I can use it at least.

#

Okay, Shape and body does work. I can use that for now.

#

Thank you!

#

It's not a perfect solution, I can tell. I had some weird speed-ups of movement when I moved my mouse around 🤔
But maybe that's due to my movement code or something.

#

You can see it happening here. The weird speed-ups in playback is when I move my mouse around in the editor while this is happening.

sonic scaffold
#

looks like fps dropped at that time

#

for some reason your movement seems tied to fps

#

chuck on vsync, do they run at the same speed?

stark totem
sonic scaffold
#

velocity doesn't need delta time applied to it

#

a velocity of 10 will move 10 units/second

#

(just to clarify, i mean if you're setting physicsvelocity.linear to a value. if you're manually applying the velocity change/frame then it should be multiplied by delta time)

stark totem
#

I am setting a constant linear velocity every frame because I wasn't sure if physical forces like collision would make it slow down