if(GetVelocity().SizeSquared()!=0)
{
UE_LOG(LogTemp, Warning, TEXT("velocity= %d , %d , %d"), GetVelocity().X, GetVelocity().Y, GetVelocity().Z);
}
I have this code in my ACharacter extended class Tick function. I have tried several variations such as GetOwner()->GetVelocity.
But the value is wrong. It was supposed to be measured in cm/s but like I say in title it gives values in millions also the values change eratically, although it does appear they stay at zero when they should and start increasing when i move.
I also tried GetCharacterMovement()->GetVelocity aswell as GetMovementComponent()->GetVelocity.
Nothing I tried has worked.
I am guessing it has something to do with how I move. But AFAIK I do it the recommended way (ie using the InputComponent property that is already part of ACharacter):
void ACopCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis("MoveForward", this, &ACopCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &ACopCharacter::MoveRight);
PlayerInputComponent->BindAxis("LookUp", this, &ACopCharacter::LookUp);
PlayerInputComponent->BindAxis("LookRight", this, &ACopCharacter::LookRight);
PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
PlayerInputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ACopCharacter::ActionCrouch);
PlayerInputComponent->BindAction("Crouch", IE_Released, this, &ACopCharacter::ActionUnCrouch);
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &ACopCharacter::ActionFireGun);
}
void ACopCharacter::MoveForward(float val)
{
if((Controller!=nullptr)&&(val!=0.0f))
{
AddMovementInput(FRotationMatrix(FRotator(0, Controller->GetControlRotation().Yaw, 0)).GetUnitAxis(EAxis::X), val);
}
}
void ACopCharacter::MoveRight(float val)
{
if((Controller!=nullptr)&&(val!=0.0f))
{
AddMovementInput(FRotationMatrix(FRotator(0, Controller->GetControlRotation().Yaw, 0)).GetUnitAxis(EAxis::Y), val);
}
Any help is much appreciated. Thank u