mirror of
https://github.com/ConjureETS/Bomberman.git
synced 2026-03-24 02:10:59 +00:00
Calculated angle from -180:180 to 0:360
This commit is contained in:
parent
aecb9f9157
commit
063735b0e6
@ -44,8 +44,7 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
//free moveDirection
|
//free moveDirection
|
||||||
Vector3 direction = camForward * moveInput.y + camTransform.right * moveInput.x;
|
Vector3 direction = camForward * moveInput.y + camTransform.right * moveInput.x;
|
||||||
|
|
||||||
float angle = Vector3.SignedAngle(Vector3.forward, direction, Vector3.up);
|
freeAngleText.text = "FreeAngle: " + Mathf.RoundToInt(GetAngle(direction));
|
||||||
freeAngleText.text = "FreeAngle: " + Mathf.RoundToInt(angle);
|
|
||||||
|
|
||||||
lastDirection = GetDirection(direction);
|
lastDirection = GetDirection(direction);
|
||||||
directionText.text = "Direction: " + lastDirection;
|
directionText.text = "Direction: " + lastDirection;
|
||||||
@ -61,23 +60,25 @@ public class PlayerMovement : MonoBehaviour {
|
|||||||
moveDirection = direction;
|
moveDirection = direction;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetRoundAngleOffset(Vector3 direction) {
|
float GetAngle(Vector3 direction) {
|
||||||
float angle = Vector3.SignedAngle(Vector3.forward, moveDirection, Vector3.up);
|
float angle = Vector3.SignedAngle(Vector3.forward, direction, Vector3.up);
|
||||||
|
if (angle < 0)
|
||||||
|
angle += 360f;
|
||||||
|
|
||||||
float deltaAngle = Mathf.Sign(angle) * 29;
|
return angle;
|
||||||
deltaAngle -= (deltaAngle + angle) % 60;
|
|
||||||
|
|
||||||
return deltaAngle;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetRoundAngleOffset(Vector3 direction)
|
||||||
|
=> 29 - (GetAngle(direction) + 29) % 60;
|
||||||
|
|
||||||
Vector3 RoundedDirection(Vector3 direction)
|
Vector3 RoundedDirection(Vector3 direction)
|
||||||
=> Quaternion.AngleAxis(GetRoundAngleOffset(direction), Vector3.up) * direction;
|
=> Quaternion.AngleAxis(GetRoundAngleOffset(direction), Vector3.up) * direction;
|
||||||
|
|
||||||
MapData.Direction GetDirection(Vector3 direction) {
|
MapData.Direction GetDirection(Vector3 direction) {
|
||||||
float angle = Vector3.SignedAngle(Vector3.forward, direction, Vector3.up);
|
float angle = GetAngle(direction);
|
||||||
float deltaAngle = GetRoundAngleOffset(direction);
|
float deltaAngle = GetRoundAngleOffset(direction);
|
||||||
|
|
||||||
int index = (Mathf.RoundToInt(angle + deltaAngle) / 60 + (Mathf.Sign(angle) < 0 ? 6 : 0)) % 6;
|
int index = (Mathf.RoundToInt(angle + deltaAngle) / 60) % 6;
|
||||||
return (MapData.Direction) index;
|
return (MapData.Direction) index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user