I have created a UE4 Project in which my character cannot jump. Please help me anyone. Any help will be appreciated. This is my Code: // Fill out your copyright notice in the Description page of Project Settings.
#include "PlayerCharacter.h"
#include "Components/InputComponent.h"
#include "GameFramework/FloatingPawnMovement.h"
#include "GameFramework/CharacterMovementComponent.h"
// Sets default values
APlayerCharacter::APlayerCharacter()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
MyMesh = CreateDefaultSubobject<UStaticMeshComponent>("MyMesh");
GetCharacterMovement()->JumpZVelocity = 600.0f;
GetCharacterMovement()->AirControl = 0.2f;
}
// Called when the game starts or when spawned
void APlayerCharacter::BeginPlay()
{
Super::BeginPlay();
bDead = false;
}
// Called every frame
void APlayerCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
}
void APlayerCharacter::Jump()
{
if (!bDead)
{
GetCharacterMovement()->AddImpulse(GetActorUpVector(), true);
AddMovementInput(GetActorUpVector(), 3.f);
};
};
I have mapped space bar Jump input in my project settings with the name ‘Jump’. My character is a sphere with simulate physics set to true. When i turn it off, my sphere falls down through the road like a ghost.
Thanks in advance!