Player Movement Input

Unreal
void APlayerChar::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent)
{
PlayerInputComponent->BindAxis("MoveForward", this, &APlayerChar::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &APlayerChar::MoveRight);
}
void MoveForward(float Value) { Move(Value, EAxis::X);}
void MoveRight(float Value) { Move(Value, EAxis::Y);}
void Move(float DirValue, EAxis::Type Axis){
                if(ThirdPerson) {
                const FRotator YawRotation(0, Controller->GetControlRotation().Yaw, 0);//#include "GameFramework/Controller.h" 
                const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(Axis);
                AddMovementInput(Direction, DirValue);
                } else if(SecondPerson) {}
                else if(FristPerson) { AddMovementInput(GetActorForwardVector(), DirValue); }
                else if(TopDown) {}
                else if(SideScroll) {}
}
Unity
void Update(){
public float plyrMovSpeed = 8;
Vector3 plyrMovment;
private void Update()
{
float movX = Input.GetAxis("Horizontal"), movZ = Input.GetAxis("Vertical");
plyrMovment = new Vector3(movX, 0, movZ);
plyrMovment *= plyrMovSpeed *Time.deltaTime;
transform.position = transform.position + plyrMovment;
}
}

Comments

Popular posts from this blog

Play Sound

Open Level

UI & Widgets