So I have a pawn which is spawned at world origin. When I use AddTorque to yaw the pawn the actor location values (namely the X and Y components of the vector) returned by GetActorLocation change as the pawn turns although the pawn itself does not move and does yaw around it’s pivot like it should.
When I use SetActorRotation to yaw the pawn it turns like with AddTorque, but the location values stay at 0 which is what I expect.
Now my pawn does not pitch or roll. Only yaw. It’s a top down asteroids style game. Perhaps I should mention that my pawn is composed of two components. Root is a UStaticMeshComponent and attached to it is a USphereComponent.
Perhaps I’m missing something. Would not be the first time.
Do you use APawn as BaseClass? Because if you use ACharacter as BaseClass or a CharacterMovementComponent, then your rotation of character is constrained to be z-up.
Keep in mind that if you translate any component of an Actor that is not the root component, then the root actually stays in place.
So if your Mesh is not the root component, then the Actor might stay in it’s place and don’t move at all.
Yes my pawn inherits directly from APawn. My pawn has a UStaticMeshComponent set as the root component.
I will try to explain my situation better. I have a camera that is looking down the positive z axis. My pawn (a spaceship) is at the world origin on the xy plane. My pawn can only move on that plane and yaw around itself. Like in the game asteroids. When my pawn is spawned it faces the x axis and at that time GetActorLocation returns the correct location which is 0, 0, 0. When I now rotate my pawn using AddTorque the pawn rotates like it should, but now the location vector returned by GetActorLocation starts to change. Namely the X and Y components of the vector. If I make a full 360 degree turn and return my pawn to face the x axis my location is again correct at 0, 0, 0.
Now if I use SetActorRotation to rotate my pawn it rotates the same way as if I had used AddTorque, but this time the location vector returned by GetActorLocation is not affected by the rotation which is how it should be because rotating my pawn does not move it’s pivot point which is at the origin.
It feels like it moves the pivot point of the pawn when I use AddTorque although the mesh itself rotates correctly around the pivot point that I have specified. Very weird
I think what you are experiencing is similar to problem I have right now. Torque and force is applied to center of mass of the object not to it’s origin. Anything that isn’t a completely symmetrical body in all thee axis will most likely have it’s center of mass away from the origin. Simple test is to replace your object with a sphere and then both center of mass and origin will be at the same spot. So torque and set rotation will provide the same result.
I don’t know if I should file it as a bug or request for new feature :eek: Being able to get or set center of mass is something very obvious for any physics based gameplay.
Yes definitely. Creating a sphere or a cube volume around my spaceship solves the problem, but does wreck havoc with my collisions. At least if you could specify a bounding volume to be used exclusively with physics calculations would solve my problem at least
EDIT: OK I can solve my problem by using a USphereComponent as the root component. This bounding volume is centered on the pivot point of my mesh. I just set it to ignore everything and that’s that.
First forget my previous post about using the sphere component as a root. I wrote it before thinking which I do a lot.
Now I got my spaceship working nicely in that using AddTorque does not “wobble” the location returned by GetActorLocation. What I did was I just used another static mesh, a sphere, as a root and I attached my spaceship mesh to it. I call AddThrust and AddTorque on that root mesh and the spaceship mesh is just along for the ride. I then set the sphere mesh to be invisible and to ignore all collisions and overlaps. It seems to work OK.
I’m not sure if this helps on your particular problem. You talked about setting and getting the object’s center of mass. In a way that is what I did. By moving the sphere mesh around I’m moving the center of mass of my spaceship mesh because the sphere mesh is the one which is affected by the physics forces and the spaceship mesh is attached to it. I hope I make sense. I’m not even sure myself
It does make sense, I’ve heard this suggestion before and should try it out. My problem is similar to yours, I just have airplane instead of spaceship.
Did you used bones to attach your mesh to the sphere? Reason why I didn’t tried this yet is because my fuselage is a root static mesh right now and wings are separate components, as soon as I enable physics simulation on anything but fuselage, it get propelled to the moon and wings are staying behind.
EDIT: By attaching I guess you mean simple placing it as a child in components hierarchy?
So, I got everything moving - following the sphere but how I can get a collision now on a mesh instead of a sphere. As soon as I enable physics on mesh - fuselage it stops following sphere and just sits in air.
Getting the collision to work should be straightforward. All you have to do is make the sphere ignore everything and then configure the mesh to handle the collisions how ever you like. I’m not 100% sure what you mean by enabling the physics on mesh fuselage. In my case the only component that has physics enabled is the sphere mesh, which is also the root component. The spaceship mesh does not have physics enabled. It wouldn’t work otherwise.
Thank you, Kumppi! I’ll try that. It’s much easier to balance forces now. I have an idea of how to triangulate a center of mass for cases when root can’t be replaced with a dummy object, I’ll post it in answers if it works.
Can’t figure it out. I’ve tried different settings but the only way I can have collision is to enable physics on child, which detaches it from root during simulation, with physics disabled I don’t get any collision. Attaching my current setup:
So it’s just doesn’t work with landscape - just flies through it. But if I place a simple box with physics enabled, I can collide with it just fine. The only issue is that none of the force of collision is transferred back to my pawn - it’s mass is 100kg and it pushes easily without stopping a box of 6647kg mass. Not sure what is going on here.
The collision happens between a non physics object (fuselage) and a physics object (simple box) and I guess that in this case the non physics object just pushes aside all physics objects.
This is just an idea and I haven’t tried it myself. It might fail miserably, but what if you enable physics on the fuselage on the point of impact or just prior to it while disabling the physics of the root object at the same time?