I’m rather new to unreal and game development, and have been working on a project with some friends through source control.
We have now been working in a sandbox level together and we all have a first person character that we’re building movement on, for practice individually. I was able to implement movement in each axis, bind a jump, add air-strafing (with AirControl), and create a sprint on my character through c++ so far.
Something I would like to implement now is a way to stop my character mid air. In my head, i would hit a movement bind and effectively cancel out my moment opposite of its direction mid air. I just don’t know how to search the unreal api properly, I can’t seem to find what to call/use through google searches.
Hi there, I hope you’re having a good day
If i got your question right, you can do it by setting the movement mode to MOVE_Falling.
The code will be something like this:
// Assuming you have a reference to your character's movement component
// stored in a variable called "MovementComponent"
MovementComponent->SetMovementMode(MOVE_Falling);
I guess my question was jumping the gun a bit, I asked such a broad question. I know c++ but within the context of unreal its like a whole new language. I guess the first step I need to do is check if the character is falling?
I was trying to use the IsFalling character movement component. Its recognized, I included the header needed too. Just for a simple check was I was going to print the bool to my screen using a debug message, but it wont let me compile without initializing the IsFalling bool (which makes me scratch my head, why define something that is a check?)
Should I somehow assign this bool’s value to another variable, then print that variable?
But if I cant initialize the bool it wont let me compile, so I really cant assign its value anyways.
// Called every frame
void AShanesTestCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//Checking and printing if falling.
bool IsFalling;
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("IsFalling: %s"), IsFalling));
}
}
oh, I’m sorry about this, my fault on understanding your question.
So, if I understood your question now, you want to check if the character is falling and then stop the movement, right?
So yeah, you have to initialize this boolean first, so your code would be something like this:
// Called every frame
void AShanesTestCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// Assuming you have a reference to your character's movement component
// stored in a variable called "MovementComponent"
bool IsFalling = MovementComponent->IsFalling();
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FString::Printf(TEXT("IsFalling: %s"), IsFalling));
}
}
I’m unclear here. You want the character to freeze in mid-air and hang there? Or you just want the character to stop moving forward and drop at an exact 90 degree angle with the floor?
I want to stop the characters forward momentum, effectively making them drop 90 degrees to the ground yes. For example, I recorded a short clip on a surf server in CounterStrike to display what I mean.
Towards the end of the first ramp, I launch off, and then hit my s key (opposite direction of my forward velocity), effectively canceling out my forward momentum.
Thank you so much for your help btw, awesome to have a community that is active
When I implement this code, it seems to like to throw an exception and end my program. Is there a way to check for nullptr when calling IsFalling, so when its first checking and im loading in it doesn’t just throw an exception?