Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

Custom Player Movement Package Documentation

Overview

The Custom Player Movement Package provides a flexible system to define and implement customized movement behaviors for players in a board game environment. By allowing the integration of mathematical functions for movement, rotation, and scaling, it allows developers to create unique animations like hopping, flipping, slithering, and more.


Key Features

  • Customizable Movement Behaviors: Define specific behaviors such as hopping, flipping, and more using mathematical functions.
  • Dynamic Components: Support for movement, rotation, and scaling on different axes.
  • Temporary Behaviors: Set temporary behaviors for a specific number of moves.

Example

Sample Scene

Here we are testing the movement on a board game. The player moves through board spaces by entering the amount of spaces into the text box and clicking "Move". You can also click next to select a different piece to move.

You can try out some of the preset behaviours by clicking on buttons labelled with "Behaviour". There are 5 presets to choose from.

1. Hopping

2. A "Big" Hop

3. Front Flipping

4. Side Flipping

5. Slithering.

There are many customisations to be made, so continue to read to see how you can make your own cool behaviour!


Getting Started

1. Initializing the Movement Controller

To set up the player movement, initialize the MovementController with a customizable behavior and movement duration.

floatmovementDuration=0.75f;CustomisableBehaviourcustom=newHopBehaviour();movementController.SetBehaviour(custom);movementController.SetMovementDuration(movementDuration);

2. Configuring Start and End Positions

Define the start and end positions for the movement:

movementController.SetStartAndEnd(Vector3start,Vector3end);

3. Updating Movement

Pass the controlled entity's transform into the Update function to apply the necessary transformations:

movementController.Update(currentTransform);

4. Checking Movement Completion

Use the MovementComplete function to determine if the movement is finished:

if(movementController.MovementComplete()){// Movement has completed}

Movement Controller Interface

Core Functions

  • Set Behavior: Assign a behavior instance to the controller.
    publicvoidSetBehaviour(CustomisableBehaviourbehaviour);
  • Set Movement Duration: Specify the duration of the movement.
    publicvoidSetMovementDuration(floatmovementDuration);
  • Define Start and End Positions:
    publicvoidSetStartAndEnd(Vector3start,Vector3end);
  • Update Movement: Apply transformations to the controlled entity’s transform.
    publicvoidUpdate(TransformcurrentTransform);
  • Check Completion: Determine if the movement act is complete.
    publicboolMovementComplete()=>isMovementComplete;

Customizable Components

The package provides interfaces to define movement, rotation, and scaling behaviors via mathematical functions:

Movement Component

Define movement functions for the axes:

publicvoidSetMovementFunction(stringaxis,Func<float,float>function);
  • Axis options: "forward", "up", "side"

Rotation Component

Define rotation functions for the axes:

publicvoidSetRotationFunction(stringaxis,Func<float,float>function);
  • Axis options: "pitch", "roll", "yaw"

Scale Component

Define scaling functions for the axes:

publicvoidSetScaleFunction(stringaxis,Func<float,float>function);
  • Axis options: "x", "y", "z"

Defining Behaviors

Behaviors can be encapsulated in classes inheriting from CustomisableBehaviour. Below is an example of a HopBehavior:

Hop Behavior Example

publicclassHopBehaviour:CustomisableBehaviour{publicHopBehaviour(){SetMovementFunction("forward", progress =>Mathf.Lerp(0,Vector3.Distance(startPosition,endPosition),progress));SetMovementFunction("up",Hop);}privatefloatHop(floatprogress){constfloatmaximumHopHeight=1.3f;floathopOffset=Mathf.Sin(progress*Mathf.PI)*maximumHopHeight;returnhopOffset;}}

Explanation:

  • Forward Movement: Linear interpolation between start and end positions.
  • Upward Movement: A sine wave creates a hopping effect, where the progress determines the height.

Combining Behaviors

Behaviors can combine movement, rotation, and scaling. For example, adding a front flip to the hop behavior:

SetRotationFunction("pitch",SpeedUpContinueAndSlowDown);publicfloatSpeedUpContinueAndSlowDown(floatprogress){constfloatrotationSpeed=360f;floatangle=Mathf.Cos(progress*Mathf.PI)*rotationSpeed;return-angle;}
  • This creates a smooth flip effect by modifying the pitch rotation.

Additional Examples

Pulse Effect

Recreate a pulse effect by setting scale functions:

publicfloatPulse(floatprogress){constfloatmaxPulseSize=1.2f;constfloatfrequencyFactor=0.5f;constfloateasingPower=3f;floateasedProgress=Mathf.Pow(progress,easingPower);floatpulse=1+Mathf.Sin(easedProgress*Mathf.PI*2*frequencyFactor)*(maxPulseSize-1);returnpulse;}SetScaleFunction("x",Pulse);SetScaleFunction("z",Pulse);

Temporary Behaviors

Define temporary behaviors for specific moves:

publicvoidSetTemporaryBehaviour(CustomisableBehaviourbehaviour,intnumberOfTempMoves);

Move to Distant Space

Use the MoveToSpace function to move to a space far away from the current position:

publicvoidMoveToSpace(intspaceNumber);

Conclusion

The Custom Player Movement Package offers a flexible system to create dynamic player animations by leveraging mathematical functions. With its modular architecture, developers can easily define, combine, and customize behaviors to create unique behaviours.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages