Dashing based on movementinput

Previously I only could dash forward based on the players forward vector, but now I want to dash based on ht players input direction. I tried this code but it just made me fly out the map:

void AJuniorProgrammerTestCharacter::Dashing()
{
	//const FVector ForwardDir = this->GetActorRotation().Vector();
	const FVector Dash = this->GetCharacterMovement()->GetActorLocation();
	if (GetCharacterMovement()->Velocity != FVector::ZeroVector) 
	{
		LaunchCharacter(Dash * DashDistance * DashSpeed, true, true);
	}
	

}

the if statement is for when the player is not moving, the dash will not activate. I learned this recently here

2 Likes

Sounds like you want to bind variables to both MoveForward and MoveRight input axes and then read the value of those to determine what direction your input is in.

1 Like

yea im trying to get their vectors and then implement the dash on it. This means that regardless of the player rotation or where its facing, i can dash based on the movement input, but i dont know how to call it

Wouldn’t it be better to use some specific key which triggers the dash, which then checks the movement direction if your character?

1 Like

Oh. And another thing.
Add a FVector(0.0f, 0.0f, 20.0f) or something similar to your dash.
It adds a little height to your dash.
Else your character will directly collide with the floor again and stop.

1 Like

sorry im quite new, how would i do that? I am already using the left shift key as the trigger for the dash

Write something like DashSpeed + FVector(0.0f, 0.0f, 20.0f)

1 Like

alright added, but the directional dash is still a problem

Does LaunchCharacter multiple the characters current velocity by that input parameter?
If your char is flying out of the map then you are pushing in too big a value.
Normalize the current velocity and use that for your dash direction and multiply by your dash amount.

I finally did it haha, it was GetLastInputVector(). As shown below:

void AJuniorProgrammerTestCharacter::Dashing()
{
	
	const FVector Dash = this->GetCharacterMovement()->GetLastInputVector();
	if (GetCharacterMovement()->Velocity != FVector::ZeroVector) 
	{
		LaunchCharacter(Dash * DashDistance * DashSpeed, true, true);
	}
	

}

This allowed my character to dash based on the direction of my input

4 Likes

Thank you guys for your help

Nicely done, happy to help.

1 Like