Hey! I am working on a momentum based jump system. It works perfectly fine, except for the fact that the x direction does not adjust to my player. That means that when I am facing a certain direction, my character is actually propelled backwards, rather than forwards. Anyone know how I could prevent this? It would be super helpful! Thank you in advance.
Here is my code:
void AFirstProjectCharacter::InitJump()
{
FVector launchVelocity = FVector(plMomentum, 0, plJumpVelocity);
if (CharacterMovement->IsMovingOnGround())
{
dJumped = false;
LaunchCharacter(launchVelocity, false, true);
}
else
{
if (!dJumped)
{
LaunchCharacter(launchVelocity, false, true);
dJumped = true;
}
}
Rama
(Rama EverNewJoy)
May 19, 2014, 10:06pm
2
#Various Info
To get the forward vector of the Character, to launch them along their current facing direction
#option 1
const FVector ForwardDir = Character->GetActorRotation().Vector();
#option 2
const FVector ForwardDir = Character->GetRootComponent()->GetForwardVector();
#Applying Force along Forward Direction
Character->CharacterMovement->Velocity += ForwardDir * 30000; //replicates automatically, if done on server
#Adding Vertical
const FVector ForwardWithZ = (ForwardDir + FVector(0,0,1)).SafeNormal(); //in case forwarddir had some Z
#Adding Vertical not world axis aligned
const FVector ForwardWithUp = (ForwardDir + Character->GetRootComponent()->GetUpVector()).SafeNormal()
#Adding Vertical with Speed and Z with Speed Separately
const FVector TotalForce = ForwardDir * ForwardSpeed + FVector(0,0,1) * UpSpeed;
Character->CharacterMovement->Velocity +=TotalForce; //replicates if done on server
where the speeds are floats
#Summary
you could use LaunchCharacter instead of my Velocity += Dir * Speed method,
the fundamental thing is you need to calculate the jumping direction , forward and vertical, more precisely.
Adapt the above basic formulas to your momentum-based system and you should be good2go.
Rama
1 Like
const FVector ForwardDir = FirstPersonCameraComponent->GetForwardVector();
const FVector AddForce = ForwardDir * plMomentum + FVector(0, 0, 1) * plJumpVelocity;
if (CharacterMovement->IsMovingOnGround())
{
dJumped = false;
LaunchCharacter(AddForce, false, true);
}
Seems to be working perfectly! Thank you very much
Rama
(Rama EverNewJoy)
May 20, 2014, 5:49pm
4
#Resolved
Yay! Glad you got it work!
(please check mark my answer if you see this so Epic knows the issue is under control)
I did. For some reason when I add a comment, it just marks it as not solved
i have done the sliding using the above method its working fine,but when i put multiplayer the slide increases as the player increases how to fix that?