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.
- 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.
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.
There are many customisations to be made, so continue to read to see how you can make your own cool behaviour!
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);Define the start and end positions for the movement:
movementController.SetStartAndEnd(Vector3start,Vector3end);Pass the controlled entity's transform into the Update function to apply the necessary transformations:
movementController.Update(currentTransform);Use the MovementComplete function to determine if the movement is finished:
if(movementController.MovementComplete()){// Movement has completed}- 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;
The package provides interfaces to define movement, rotation, and scaling behaviors via mathematical functions:
Define movement functions for the axes:
publicvoidSetMovementFunction(stringaxis,Func<float,float>function);- Axis options:
"forward","up","side"
Define rotation functions for the axes:
publicvoidSetRotationFunction(stringaxis,Func<float,float>function);- Axis options:
"pitch","roll","yaw"
Define scaling functions for the axes:
publicvoidSetScaleFunction(stringaxis,Func<float,float>function);- Axis options:
"x","y","z"
Behaviors can be encapsulated in classes inheriting from CustomisableBehaviour. Below is an example of a HopBehavior:
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;}}- Forward Movement: Linear interpolation between start and end positions.
- Upward Movement: A sine wave creates a hopping effect, where the
progressdetermines the height.
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.
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);Define temporary behaviors for specific moves:
publicvoidSetTemporaryBehaviour(CustomisableBehaviourbehaviour,intnumberOfTempMoves);Use the MoveToSpace function to move to a space far away from the current position:
publicvoidMoveToSpace(intspaceNumber);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.