This commit is contained in:
2025-05-11 00:46:26 +08:00
parent 366f9e95ec
commit 618f75f911
2404 changed files with 154475 additions and 924730 deletions

View File

@@ -0,0 +1,34 @@
using UnityEngine;
namespace ECM2.Examples.SlopeSpeedModifier
{
/// <summary>
/// This example shows how to extend a Character (through inheritance) to modify its speed
/// based on current slope angle.
/// </summary>
public class MyCharacter : Character
{
/// <summary>
/// Returns the Character's current speed modified by slope angle.
/// </summary>
public override float GetMaxSpeed()
{
float maxSpeed = base.GetMaxSpeed();
float slopeAngle = GetSignedSlopeAngle();
float speedModifier = slopeAngle > 0.0f
? 1.0f - Mathf.InverseLerp(0.0f, 90.0f, +slopeAngle) // Decrease speed when moving up-slope
: 1.0f + Mathf.InverseLerp(0.0f, 90.0f, -slopeAngle); // Increase speed when moving down-slope
return maxSpeed * speedModifier;
}
private void OnGUI()
{
GUI.Label(new Rect(10, 10, 400, 20),
$"Slope angle: {GetSignedSlopeAngle():F2} maxSpeed: {GetMaxSpeed():F2} ");
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ed4928a0889cacc45a74216577a2ff32
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: