UnrealScripterAI
Discord ↗
Link Copied to Clipboard
×
"movement system"
// Implement a basic movement system in Unreal // Add this to your character's header file UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float MovementSpeed; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement") float RotationSpeed; // Add this to your character's source file void AMyCharacter::MoveForward(float Value) { FVector Forward = GetActorForwardVector(); AddMovementInput(Forward, Value * MovementSpeed * GetWorld()->GetDeltaSeconds()); } void AMyCharacter::MoveRight(float Value) { FVector Right = GetActorRightVector(); AddMovementInput(Right, Value * MovementSpeed * GetWorld()->GetDeltaSeconds()); } void AMyCharacter::Turn(float Value) { FRotator NewRotation = GetActorRotation(); NewRotation.Yaw = Value * RotationSpeed * GetWorld()->GetDeltaSeconds(); SetActorRotation(NewRotation); } // Add this to your character's BeginPlay() method InputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward); InputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight); InputComponent->BindAxis("Turn", this, &AMyCharacter::Turn);