x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Variable Jump Height with a rolling ball, fluctuating with different FPS

I want to have a variable jump height when jumping (the longer the jump button is held, the higher you jump). It generally works fine, but when I set the Max FPS to different amounts, the jump height changes (lower FPS = higher jump height).

JumpState is 0 if the player is able to jump, 1 while jumping is accelerated in the air and 2 when falling. JumpTimer is the amount how long the button has been pressed, if it reaches JumpTimerMax, JumpState is set to 2. JumpAdd is the amount that gets added to the Z velocity each tick (multiplied by DeltaSeconds)

Relevant code:

 void ATestingBallBall::JumpPressed()
 {
     if (JumpState == 0)
     {
         Ball->SetPhysicsLinearVelocity(Ball->GetComponentVelocity() + FVector(0,0,JumpStart));
         JumpState = 1;
         JumpTimer = 0;
     }
 }

 void ATestingBallBall::JumpReleased()
 {
     JumpState = 2;
 }

 void ATestingBallBall::Tick(float DeltaSeconds)
 {
     if (JumpState == 1)
     {
         Ball->SetPhysicsLinearVelocity(Ball->GetComponentVelocity() + FVector(0, 0, JumpAdd*DeltaSeconds));
         JumpTimer += DeltaSeconds;
         if (JumpTimer >= JumpTimerMax)
         {
             JumpState = 2;
         }
     }
 }

Product Version: UE 4.15
Tags:
more ▼

asked May 01 '17 at 01:11 PM in C++ Programming

avatar image

Bingo90
1 1 1

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Basically by using FVector(0, 0, JumpAdd*DeltaSeconds) you apply an acceleration of length JumpAdd every Tick call. This is like applying an impulse of the same strength each Tick call. So my guess would be to use JumpAdd*DeltaSeconds*DeltaSeconds instead which makes the impulse linear proportional to DeltaSeconds.

(Please notice that Euler intergration underlies my answer, and it does not provide correct physic simulation)

more ▼

answered May 01 '17 at 03:15 PM

avatar image

Benergy
816 21 4 28

avatar image Bingo90 May 01 '17 at 04:24 PM

Unfortunately, this just causes the problem to be even worse.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question