Announcement

Collapse
No announcement yet.

AddTorque and GetActorLocation weirdness

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    AddTorque and GetActorLocation weirdness

    Howdy folks,

    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.

    I call AddTorque in my pawn class like this...

    Code:
    FVector Torque = FVector::UpVector * ((TorqueForce * TurnInputVal) * DeltaSeconds);
    Mesh->AddTorque(Torque);
    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.

    #2
    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.

    Comment


      #3
      Thanks for the reply.

      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

      Comment


        #4
        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.
        Youtube Channel

        Comment


          #5
          That's interesting. I will try it with a sphere and see what the results are. Thank you.

          You are correct. With sphere the location does not move while rotating with AddTorque.
          Last edited by Kumppi; 09-15-2014, 07:54 AM.

          Comment


            #6
            I don't know if I should file it as a bug or request for new feature Being able to get or set center of mass is something very obvious for any physics based gameplay.
            Youtube Channel

            Comment


              #7
              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.
              Last edited by Kumppi; 09-15-2014, 09:39 AM.

              Comment


                #8
                So does the rest of your mesh actually works with proper collision and etc?
                Youtube Channel

                Comment


                  #9
                  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

                  Comment


                    #10
                    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?
                    Last edited by BoredEngineer; 09-16-2014, 09:21 AM.
                    Youtube Channel

                    Comment


                      #11
                      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.
                      Last edited by BoredEngineer; 09-16-2014, 04:35 PM.
                      Youtube Channel

                      Comment


                        #12
                        Yes I attached it as a child.

                        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.

                        Comment


                          #13
                          Do you mean that you have collision enabled only on mesh and physics only on sphere?
                          Youtube Channel

                          Comment


                            #14
                            Yes.

                            To be more precise the sphere has collisions enabled. I just made it ignore everything. It didn't seem to work if I disabled collisions altogether.

                            Comment


                              #15
                              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.
                              Youtube Channel

                              Comment

                              Working...
                              X