Character Continously Jumping

Hi,

I am trying to program some jump functionality with my character. When i play he is not jumping, but on the initial jump button when its pressed he jumps as intended but then carries on jumping after which is not intended.

TrainingCharacter.h

    UPROPERTY(BlueprintReadOnly, Category = "Character")
bool bCanJump;

UPROPERTY(BlueprintReadOnly, Category = "Character")
bool bIsJumping;

/** The character starts jumping*/
virtual void JumpStart();

/** The character stops jumping*/
virtual void JumpStop();

TrainingCharacter.cpp

ATrainingCharacter::ATrainingCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
    	this->bCanJump = false;
	this->bIsJumping = false;
}

void ATrainingCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{

	InputComponent->BindAction("Jump", IE_Pressed, this, &ATrainingCharacter::JumpStart);
	InputComponent->BindAction("Jump", IE_Released, this, &ATrainingCharacter::JumpStop);
}

void ATrainingCharacter::JumpStart()
{
	this->bCanJump = true;
}
void ATrainingCharacter::JumpStop()
{
	this->bCanJump = false;
}

MyAnimInstance.h

UPROPERTY(EditDefaultsOnly, BluePrintReadOnly, Category = "Character")
bool bCanJump;

MyAnimInstance.cpp

void UMyAnimInstance::BlueprintUpdateAnimation(float DeltaTimeX)
{
	Super::BlueprintUpdateAnimation(DeltaTimeX);

	if (this->Character != NULL)
	{
		this->bCanJump = this->Character->bCanJump;
	}
}

Locomotion Blueprints

http://i.imgur.com/xCLMtKN.png
http://i.imgur.com/wEWa2HO.png
http://i.imgur.com/ga7TYOS.png
http://i.imgur.com/sLho8n3.png

This is all i have done on jumping as this project is created from scratch. Can someone tell me what i need to do to stop him from constantly jumping. My initial idea was to have a variable of “canJump” be set to true when ever a person hits the jump button, then on release it sets the “canJump” button back to false.

i think instead of just set the bCanJumpFlag. in the character class there is a function named ::

  • Jump()
  • StopJumping()

you can use that in your press event.

and i also wondering about your animation… are you using the state machine?? (locomotion??) i think you had to take a look at the thirdpersoncharacter from unreal. because i think your problem also implies the animation (if you just stay in the jump animation state after you jump).

cherrs…

@mirsabayu

Why would i need to use the Jump() and StopJumping() functions? What do they do? Can i not just re-create these in c++ as i think they use some blueprint functionality right?

Sorry, i don’t understand what you mean regarding the animation. If you check my question you will see i provided links of the locomotion. Can you please explain what you mean?

Right i get this. In the AnimBlueprint i have retargeted to my custom animblueprint i created in c++. So the variable in the eventgraph “Jump Button Down” does not compile as it can’t find it. How can i fix this? I have tried searching for where this is initialised in the Character class but i can’t seem to find it

ive alrdy provided with the state machine its here. http://i.imgur.com/xCLMtKN.png

And the animgraph is only the Locomotion connecting to final animation pose.

/**
* Make the character jump on the next update.
* If you want your character to jump according to the time that the jump key is held,
* then you can set JumpKeyHoldTime to some non-zero value. Make sure in this case to
* call StopJumping() when you want the jump’s z-velocity to stop being applied (such
* as on a button up event), otherwise the character will carry on receiving the
* velocity until JumpKeyHoldTime is reached.
*/
UFUNCTION(BlueprintCallable, Category=“Pawn|Character”)
virtual void Jump();

/** 
 * Stop the character from jumping on the next update. 
 * Call this from an input event (such as a button 'up' event) to cease applying
 * jump Z-velocity. If this is not called, then jump z-velocity will be applied
 * until JumpMaxHoldTime is reached.
 */
UFUNCTION(BlueprintCallable, Category="Pawn|Character")
virtual void StopJumping();

== the implementation ==

void ACharacter::Jump()
{
bPressedJump = true;
JumpKeyHoldTime = 0.0f;
}

void ACharacter::StopJumping()
{
bPressedJump = false;
JumpKeyHoldTime = 0.0f;
}

from ACharacter class in cpp, maybe it can help. so it’s not a blueprint. it was a cpp function that expose in blueprint;

and as for animation. is it a state in the state machine?? (and what stat??) i think it’s better if you provide the animgraph and also the statemachine in that.

sorry, i seems can’t find your eventgraph. i think if you use your own customAnimInstance. i think the problem, is really gonna be simpler. because you can call your animationInstance using the skeletalMesh on your character class. but anyway, maybe i seems not really understand what you wanted to achieve. as i see in your stateMachine/locomotion what i see is just a three state right. so when it want to jump in the transition condition you feed it with a bool that you get from charactermovement->isFalling() right?? and that goes the same with the landing (just feed the not IsFalling in the transition condition). - but maybe you will not get a very satisfying animation (because what i know, like thirdperson project give us. it break to 3 state (jumpstart, jumploop, and jumpend)

sorry if it not help much jejeje

Thnx anyway hopefully someone else might know