Tweak movement

This commit is contained in:
Jens Pitkänen 2020-08-10 02:27:48 +03:00
parent 5fd67e0c6a
commit 2dcea14729
7 changed files with 52 additions and 34 deletions

View File

@ -240,6 +240,24 @@ MonoBehaviour:
DisableInput: 0
SyncInterval: 0.5
MovementUpdateInterval: 0.03
--- !u!114 &3537472584083277103
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 7808238467771803924}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 22a7da1b361417640853a9cdcde28400, type: 3}
m_Name:
m_EditorClassIdentifier:
Player: {fileID: 7626229210202316125}
InterpolationSpeed: 5
YawDegrees: 4
PitchDegrees: 4
RollDegrees: 6
RotationThreshold: 5
--- !u!1 &8414821799312552490
GameObject:
m_ObjectHideFlags: 0
@ -817,3 +835,8 @@ Transform:
m_CorrespondingSourceObject: {fileID: 4833458671639168932, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0}
--- !u!1 &7808238467771803924 stripped
GameObject:
m_CorrespondingSourceObject: {fileID: 2071588178488902664, guid: 0bffd92c46c257840806f5e957954800, type: 3}
m_PrefabInstance: {fileID: 8134536652936637724}
m_PrefabAsset: {fileID: 0}

View File

@ -109,7 +109,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1607323028047207915}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.02, z: 0}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 4103164600241655739}
@ -508,7 +508,7 @@ MonoBehaviour:
GroundCastLength: 0.2
GroundLayer:
serializedVersion: 2
m_Bits: 11009
m_Bits: 10497
ShowGroundCast: 0
ShowMoveVector: 0
--- !u!1 &7391558913556166741

View File

@ -13,7 +13,7 @@ MonoBehaviour:
m_Name: Crouching
m_EditorClassIdentifier:
TargetVelocity: 6
StopVelocity: 3
StopVelocity: 4
Acceleration: 20
AirAcceleration: 15
Friction: 20

View File

@ -13,8 +13,8 @@ MonoBehaviour:
m_Name: Running
m_EditorClassIdentifier:
TargetVelocity: 11
StopVelocity: 3
Acceleration: 7
StopVelocity: 6
Acceleration: 9
AirAcceleration: 5
Friction: 6
AirFriction: 2

View File

@ -14,10 +14,6 @@ namespace NeonTea.Quakeball.Animation {
private Vector2 CurrentLean = Vector2.zero;
private Vector2 TargetLean = Vector2.zero;
private void Awake() {
transform.parent = Player.Player.CameraRoot;
}
private void Update() {
Vector2 LookDelta = Player.LookAction.ReadValue<Vector2>();
SetTarget(LookDelta.x, ref TargetLean.x);

View File

@ -21,9 +21,9 @@ namespace NeonTea.Quakeball.Animation {
public Transform GunHandle;
private Animator Animator;
private float BodyYaw = 0;
private Transform BehindHand;
private Transform FrontHand;
private Transform Head;
private void Awake() {
foreach (Animator animator in Soldiers) {
@ -31,7 +31,7 @@ namespace NeonTea.Quakeball.Animation {
}
Animator = Soldiers[(int)Model].GetComponent<Animator>();
Animator.gameObject.SetActive(true);
HeadCollider.parent = TransformUtil.FindChildWithName(Animator.transform, "HEAD");
HeadCollider.parent = Head = TransformUtil.FindChildWithName(Animator.transform, "HEAD");
BehindHand = TransformUtil.FindChildWithName(Animator.transform, "HAND.R");
FrontHand = TransformUtil.FindChildWithName(Animator.transform, "HAND.L");
if (GunGluedToHand) {
@ -48,6 +48,7 @@ namespace NeonTea.Quakeball.Animation {
private void LateUpdate() {
transform.localEulerAngles = new Vector3(0, Player.Yaw, 0);
Head.localEulerAngles = new Vector3(Player.Pitch, 0, 0);
if (GunGluedToHand) {
Vector3 GunOffset = GunHandle.position - Gun.position;

View File

@ -133,19 +133,6 @@ namespace NeonTea.Quakeball.Players {
return ShouldApply;
}
/// <summary>The normal of the ground below the player. If there is no ground, it's <c>Vector3.up</c> by default.</summary>
public Vector3 GroundCast() {
RaycastHit Hit;
if (ShowGroundCast) {
Debug.DrawLine(FeetPosition, FeetPosition - Vector3.up, Color.red, 1f);
}
if (Physics.Raycast(FeetPosition, -Vector3.up, out Hit, GroundCastLength, GroundLayer)) {
return Hit.normal;
} else {
return Vector3.up;
}
}
public bool Jump() {
bool IsCoyoteTime = Time.time - GroundedTime <= CoyoteTime + PingBias;
if (IsCoyoteTime || IsGrounded()) {
@ -249,6 +236,20 @@ namespace NeonTea.Quakeball.Players {
return CharacterController.isGrounded && Vector3.Dot(GravitationalVelocity, Vector3.down) >= 0;
}
/// <summary>The normal of the ground below the player. If there is no ground, it's <c>Vector3.up</c> by default.</summary>
private Vector3 GroundCast() {
RaycastHit hit;
Vector3 feetPosition = FeetPosition + transform.position + CharacterController.center + Vector3.down * CharacterController.height / 2;
if (ShowGroundCast) {
Debug.DrawLine(feetPosition, feetPosition - Vector3.up, Color.red, 1f);
}
if (Physics.Raycast(feetPosition, -Vector3.up, out hit, GroundCastLength, GroundLayer)) {
return hit.normal;
} else {
return Vector3.up;
}
}
private void Awake() {
CharacterController = GetComponent<CharacterController>();
FeetPosition = transform.position + CharacterController.center - Vector3.up * (CharacterController.height / 2 + CharacterController.skinWidth / 2);
@ -278,7 +279,7 @@ namespace NeonTea.Quakeball.Players {
bool FallingDown = Vector3.Dot(Vector3.down, GravitationalVelocity) > 0;
if (Grounded && FallingDown) {
GravitationalVelocity = Vector3.zero;
GravitationalVelocity = GroundCastLength * Vector3.down;
} else if (!Grounded) {
GravitationalVelocity += Physics.gravity * Time.deltaTime;
}
@ -305,22 +306,19 @@ namespace NeonTea.Quakeball.Players {
Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed);
GroundVelocity += FixedHeading * Acceleration;
Vector3 FinalMoveVector = GroundVelocity + GravitationalVelocity;
CharacterController.Move(FinalMoveVector * Time.deltaTime);
CharacterController.Move(GroundVelocity * Time.deltaTime);
CollisionFlags flags = CharacterController.Move(GravitationalVelocity * Time.deltaTime);
if (CharacterController.isGrounded) {
GroundedTime = Time.time;
LatestGroundedY = transform.position.y;
}
if (GravitationalVelocity.y > 0.1 && Mathf.Abs(CharacterController.velocity.y) < 0.1) {
// Hit a roof while jumping
GravitationalVelocity.y = 0;
// Hit a roof while jumping, reset falling velocity downwards (same as "static gravity" when grounded)
GravitationalVelocity.y = GroundCastLength;
}
if (ShowMoveVector) {
Debug.DrawLine(
transform.position + CharacterController.center,
transform.position + CharacterController.center + FinalMoveVector,
Color.green, 1.0f
);
Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GravitationalVelocity, Color.yellow, 1.0f);
Debug.DrawLine(transform.position + CharacterController.center, transform.position + CharacterController.center + GroundVelocity, Color.green, 1.0f);
}
float TargetBobbiness = Grounded ? GroundVelocity.magnitude / MoveStyle.TargetVelocity : 0;