Допил наклонов (они такое себе)
Хуже, чем были раньше, но лучше, чем ничего. Плавность переходов имеется, и на том спасибо
This commit is contained in:
1 parent
766609489d
commit
4b6909fe84
3 files changed
+63
-46
No files matched your search
+55
-36
@@ -4,56 +4,75 @@ namespace Code.Gameplay.Character.Controller.Abilities
|
||||
{
|
||||
public class WallLeanMechanic
|
||||
{
|
||||
private readonly float _leanAngle;
|
||||
private readonly float _threshold;
|
||||
private readonly float _smoothSpeed;
|
||||
|
||||
private Transform _model;
|
||||
|
||||
public WallLeanMechanic(
|
||||
float leanAngle,
|
||||
float threshold,
|
||||
float smoothSpeed)
|
||||
{
|
||||
_leanAngle = leanAngle;
|
||||
_threshold = threshold;
|
||||
_smoothSpeed = smoothSpeed;
|
||||
}
|
||||
|
||||
public void SetModel(Transform model) => _model = model;
|
||||
|
||||
public void Update(bool isWallRunning, Vector3 wallNormal, Vector3 characterForward)
|
||||
{
|
||||
if (_model == null)
|
||||
if (!_model)
|
||||
{
|
||||
_model.localRotation = Quaternion.identity;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isWallRunning)
|
||||
var targetRotation = Quaternion.identity;
|
||||
|
||||
if (isWallRunning)
|
||||
{
|
||||
_model.localRotation = Quaternion.identity;
|
||||
return;
|
||||
var n = new Vector3(wallNormal.x, 0f, wallNormal.z).normalized;
|
||||
if (n.sqrMagnitude < 0.001f) n = Vector3.forward;
|
||||
|
||||
var bodyRight = Vector3.Cross(Vector3.up, characterForward).normalized;
|
||||
var side = Vector3.Dot(n, bodyRight);
|
||||
var front = Vector3.Dot(n, characterForward);
|
||||
|
||||
var axis = Vector3.right;
|
||||
var angle = 0f;
|
||||
|
||||
if (side > _threshold)
|
||||
{
|
||||
axis = Vector3.forward;
|
||||
angle = -_leanAngle;
|
||||
}
|
||||
else if (side < -_threshold)
|
||||
{
|
||||
axis = Vector3.forward;
|
||||
angle = _leanAngle;
|
||||
}
|
||||
else if (front > _threshold)
|
||||
{
|
||||
axis = Vector3.right;
|
||||
angle = -_leanAngle;
|
||||
}
|
||||
else if (front < -_threshold)
|
||||
{
|
||||
axis = Vector3.right;
|
||||
angle = _leanAngle;
|
||||
}
|
||||
|
||||
targetRotation = Quaternion.AngleAxis(angle, axis);
|
||||
}
|
||||
|
||||
Vector3 n = new Vector3(wallNormal.x, 0f, wallNormal.z).normalized;
|
||||
if (n.sqrMagnitude < 0.001f) n = Vector3.forward;
|
||||
|
||||
Vector3 bodyRight = Vector3.Cross(Vector3.up, characterForward).normalized;
|
||||
float side = Vector3.Dot(n, bodyRight);
|
||||
float front = Vector3.Dot(n, characterForward);
|
||||
|
||||
Vector3 axis = Vector3.right;
|
||||
float angle = 0f;
|
||||
|
||||
if (side > 0.3f)
|
||||
{
|
||||
axis = Vector3.forward;
|
||||
angle = -25f;
|
||||
}
|
||||
else if (side < -0.3f)
|
||||
{
|
||||
axis = Vector3.forward;
|
||||
angle = 25f;
|
||||
}
|
||||
else if (front > 0.3f)
|
||||
{
|
||||
axis = Vector3.right;
|
||||
angle = -25f;
|
||||
}
|
||||
else if (front < -0.3f)
|
||||
{
|
||||
axis = Vector3.right;
|
||||
angle = 25f;
|
||||
}
|
||||
|
||||
_model.localRotation = Quaternion.AngleAxis(angle, axis);
|
||||
_model.localRotation = Quaternion.Slerp(
|
||||
_model.localRotation,
|
||||
targetRotation,
|
||||
1f - Mathf.Exp(-_smoothSpeed * Time.deltaTime)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,9 @@ namespace Code.Gameplay.Character.Controller
|
||||
_wallRunningMechanic.WallContactAngleThreshold = 45.0f;
|
||||
|
||||
_wallLeanMechanic = new WallLeanMechanic(
|
||||
_characterConfig.leanAngle,
|
||||
_characterConfig.leanThreshold,
|
||||
_characterConfig.leanSmoothSpeed
|
||||
);
|
||||
_groundMovement = new GroundMovementSystem(
|
||||
_characterConfig.maxStableMoveSpeed,
|
||||
|
||||
Reference in new issue
Block a user