Announcement

Collapse
No announcement yet.

How to stop character moving with floor?

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

    How to stop character moving with floor?

    Hi everyone
    I setup a floor moving along the X axis.Now my character is moving with it.How can I stop the character moving with floor so if the player don't jump the chatacter will fall from the end of the moving floor?

    #2
    Get the velocity of the moving platform, multiply it by -1 and add it to the players velocity, this might get glitchy though.
    My Game Frontier Devblog HERE

    Comment


      #3
      If you're using the default character, then in the movement component cpp file there is this function:

      Code:
      void UCharacterMovementComponent::UpdateBasedMovement(float DeltaSeconds)
      {
          if (!HasValidData())
          {
              return;
          }
      
          const UPrimitiveComponent* MovementBase = CharacterOwner->GetMovementBase();
          if (!MovementBaseUtility::UseRelativeLocation(MovementBase))
          {
              return;
          }
      
          if (!IsValid(MovementBase) || !IsValid(MovementBase->GetOwner()))
      
      //...
      And I'm suspecting that function has to do with it? So maybe you can inherit from UCharacterMovementComponent and just add an override to that function (since is virtual) which exit from the function based on a variable you control, like "bIsOnActiveMovingPlatform"

      And then if your character inherits from C++, you can unregister the default move component and register this new one from the C++ constructor, I believe.

      But is all speculation, I don't really know

      Comment


        #4
        Originally posted by Orkney View Post
        Get the velocity of the moving platform, multiply it by -1 and add it to the players velocity, this might get glitchy though.
        Hi Orkeny,Thanks for your idea.I tried on a test project.It worked but the character was shaking,may be because of the inaccuracy in real time,and it may get tricky if I put some other movement into the game.But thank you anyway.

        Comment


          #5
          Originally posted by ムリですよ View Post
          If you're using the default character, then in the movement component cpp file there is this function:

          Code:
          void UCharacterMovementComponent::UpdateBasedMovement(float DeltaSeconds)
          {
          if (!HasValidData())
          {
          return;
          }
          
          const UPrimitiveComponent* MovementBase = CharacterOwner->GetMovementBase();
          if (!MovementBaseUtility::UseRelativeLocation(MovementBase))
          {
          return;
          }
          
          if (!IsValid(MovementBase) || !IsValid(MovementBase->GetOwner()))
          
          //...
          And I'm suspecting that function has to do with it? So maybe you can inherit from UCharacterMovementComponent and just add an override to that function (since is virtual) which exit from the function based on a variable you control, like "bIsOnActiveMovingPlatform"

          And then if your character inherits from C++, you can unregister the default move component and register this new one from the C++ constructor, I believe.

          But is all speculation, I don't really know
          Hi ,thanks for your reply.
          I'm not familiar with C++.It seems that the only way to add a subclass of UCharacterMovementComponent to an actor is through C++ because it's an actor component, is that right?

          Comment


            #6
            Originally posted by Surtur View Post

            Hi ,thanks for your reply.
            I'm not familiar with C++.It seems that the only way to add a subclass of UCharacterMovementComponent to an actor is through C++ because it's an actor component, is that right?
            I don't know why actually :P
            Though maybe the problem multipling by -1 is that you get small floating point rounding imprecisions? Instead I would try setting a bool on the character when your platform is moving, and when the bool is set you store your character current location at that frame, and then next frame you move it to the same location, so no multiplication involved.
            If this get rid of the glitches, then you can take it from there and move him every tick at that location if he doesn't move, or as starting location for the next movement.
            Also I do believe that the UCharacterMovementComponent that comes with your default character also give you the option to switch between several moving mode, like "fly", "crouch", "swim" and there is also a "Custom".
            So maybe you can switch to Custom movement mode while on top of a moving platform and revert back to "Walk" while not.

            Though I don't know if this Custom thing can be set in blueprint or not, never done this stuff :P
            Last edited by ムリですよ; 03-20-2018, 04:04 AM.

            Comment


              #7
              Originally posted by ムリですよ View Post

              I don't know why actually :P
              Though maybe the problem multipling by -1 is that you get small floating point rounding imprecisions? Instead I would try setting a bool on the character when your platform is moving, and when the bool is set you store your character current location at that frame, and then next frame you move it to the same location, so no multiplication involved.
              If this get rid of the glitches, then you can take it from there and move him every tick at that location if he doesn't move, or as starting location for the next movement.
              Also I do believe that the UCharacterMovementComponent that comes with your default character also give you the option to switch between several moving mode, like "fly", "crouch", "swim" and there is also a "Custom".
              So maybe you can switch to Custom movement mode while on top of a moving platform and revert back to "Walk" while not.

              Though I don't know if this Custom thing can be set in blueprint or not, never done this stuff :P
              Hi ムリですよ , I tried your UpdateBaseMovement idea.It worked.The character didn't move with the floor and fell off the edge.
              Thanks.

              Comment


                #8
                Originally posted by ムリですよ View Post

                I don't know why actually :P
                Though maybe the problem multipling by -1 is that you get small floating point rounding imprecisions? Instead I would try setting a bool on the character when your platform is moving, and when the bool is set you store your character current location at that frame, and then next frame you move it to the same location, so no multiplication involved.
                If this get rid of the glitches, then you can take it from there and move him every tick at that location if he doesn't move, or as starting location for the next movement.
                Also I do believe that the UCharacterMovementComponent that comes with your default character also give you the option to switch between several moving mode, like "fly", "crouch", "swim" and there is also a "Custom".
                So maybe you can switch to Custom movement mode while on top of a moving platform and revert back to "Walk" while not.

                Though I don't know if this Custom thing can be set in blueprint or not, never done this stuff :P
                Thats nice, thankyou for that information never thought of tackling it that way
                My Game Frontier Devblog HERE

                Comment


                  #9
                  Originally posted by Surtur View Post

                  Hi ムリですよ , I tried your UpdateBaseMovement idea.It worked.The character didn't move with the floor and fell off the edge.
                  Thanks.
                  Wait, with "I tried your UpdateBaseMovement idea" you mean the C++ idea about inheriting from the UCharacterMovementComponent and overriding the UpdateBaseMovement method?!
                  I actually attempted that too out of curiousity, but I failed to tell the character to use my movement component instead of the default UCharacterMovementComponent it gets when it is constructed.

                  If you managed to make it work, can you show me how did you substituted his default UCharacterMovementComponent for yours? :P

                  Comment


                    #10
                    Nevermind, I had a small error in the code, now the C++ version works as well

                    Comment


                      #11
                      Originally posted by ムリですよ View Post

                      Wait, with "I tried your UpdateBaseMovement idea" you mean the C++ idea about inheriting from the UCharacterMovementComponent and overriding the UpdateBaseMovement method?!
                      I actually attempted that too out of curiousity, but I failed to tell the character to use my movement component instead of the default UCharacterMovementComponent it gets when it is constructed.

                      If you managed to make it work, can you show me how did you substituted his default UCharacterMovementComponent for yours? :P
                      Sorry for not replying you for so long.I didn't check out message recently.
                      you can find how to change character movement component in here

                      Comment

                      Working...
                      X