using UnityEngine;
namespace ECM2.Examples.TwinStickMovement
{
///
/// This example shows how to extend a Character (through inheritance), adding a custom rotation mode;
/// in this case, implements a typical Mouse and Keyboard twin-stick shooter control.
///
public class TwinStickCharacter : Character
{
private Vector3 _aimDirection;
///
/// Returns the current aim direction vector.
///
public virtual Vector3 GetAimDirection()
{
return _aimDirection;
}
///
/// Sets the desired aim direction vector (in world space).
///
public virtual void SetAimDirection(Vector3 worldDirection)
{
_aimDirection = worldDirection;
}
///
/// Use a custom rotation mode to rotate towards aim direction (if shooting)
/// or towards movement direction if not.
///
/// The simulation delta time
protected override void CustomRotationMode(float deltaTime)
{
// Call base method implementation
base.CustomRotationMode(deltaTime);
// Update character rotation
Vector3 targetDirection =
_aimDirection.isZero() ? GetMovementDirection() : GetAimDirection();
RotateTowards(targetDirection, deltaTime);
}
}
}