Cover for the App

Player Movement with Music

A sample project that features character's movement, animations, and sounds, with a camera that follows the character smoothly.

A sample project that features character's movement, animations, and sounds, with a camera that follows the character smoothly.

Player Movement with Music

Overview

This project is a simulation that allows players to control a character in a virtual terrain. The character features realistic movement mechanics and audio cues, making for an immersive experience. The project includes a character controller and a follow camera system to enhance gameplay.

Controls

Use the following keys to control the character:

  • 'W' or Up Arrow: Move forward
  • 'S' or Down Arrow: Move backward
  • 'A' or Left Arrow: Turn left
  • 'D' or Right Arrow: Turn right
  • 'W + A': Move forward and turn left (diagonal movement)
  • 'W + D': Move forward and turn right (diagonal movement)
  • 'S + A': Move backward and turn left (diagonal movement)
  • 'S + D': Move backward and turn right (diagonal movement)

Components

1. Character Controller

The component enables keyboard-controlled movement mechanics. It uses a state machine to manage the character's behavior, switching between idle and moving states.

Schema:

  • speed: The speed at which the character moves forward or backward.

Data:

  • currentAngle: Tracks the current rotation angle of the character.
  • currentState: Stores the current state of the character (idle or moving).

State Machine:

  • Idle State: Activated when the character is not moving. Transitions to the "moving" state when input is detected.
  • Moving State: Activated when the character is in motion. Transitions back to "idle" when input stops.

The state machine improves organization, providing a framework for expanding character behaviors. For example, it could manage animations or trigger additional features like power consumption.

2. Follow Camera

The component ensures that the camera smoothly tracks the character. This enhances the gameplay experience by maintaining a consistent view of the character.

Schema:

  • target: Reference to the target entity (e.g., the character).
  • camera: Reference to the camera entity.
  • offsetX, offsetY, offsetZ: Specify the camera's offset relative to the character.

3. Input Manager

The Input Manager maps various inputs to control the character, supporting seamless interaction across devices.

Actions:

  • forward: Moves the character forward.
  • backward: Moves the character backward.
  • left: Rotates the character left.
  • right: Rotates the character right.

Input mappings include:

  • Keyboard: 'W', 'S', 'A', 'D' and arrow keys.
  • Gamepad: Left joystick and D-pad inputs.

Key Features

Character Controller

The component adds dynamic movement to the character. It manages animations and audio based on the character's state.

Features:

  • Idle State: Plays idle animations and stops audio.
  • Moving State: Plays walking animations and bubble footstep audio.
  • Diagonal Movement: Detects diagonal inputs for smoother control.

Schema:

  • speed: Defines movement speed.
  • character: Reference to the character entity.

Camera Follower

The component ensures the camera tracks the character with customizable offsets.

Schema:

  • player: Reference to the player entity.
  • camera: Reference to the camera entity.
  • offsetX, offsetY, offsetZ: Configurable camera offsets for optimal positioning.

Audio

  • bubbleFootsteps.mp3: This sound plays when the character is in motion, enhancing the immersive experience.

Future Enhancements

  • Add animations for terrain interaction.
  • Introduce power and fuel management systems.
  • Enable multiplayer functionality.