Add a bob

This commit is contained in:
Jens Pitkänen 2020-08-06 00:15:28 +03:00
parent 71fadf9fd4
commit dd3599c79a
3 changed files with 149 additions and 7 deletions

View File

@ -4284,6 +4284,43 @@ MonoBehaviour:
CrouchingMoveStyle: {fileID: 11400000, guid: 2d9739d3745581a41ae0ed6a569766d5, type: 2}
Head: {fileID: 1691001572}
Body: {fileID: 824052665}
Gun: {fileID: 539510584}
GunBobFrom: {x: 0, y: 0, z: 0}
GunBobTo: {x: 0, y: 0, z: -0.1}
GunBobFrequency: 1.5
GunBobCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: -0.0023498535
inSlope: 0.31635603
outSlope: 0.31635603
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 0.8411595
- serializedVersion: 3
time: 0.5248914
value: 0.61688983
inSlope: -4.694472
outSlope: -4.694472
tangentMode: 0
weightedMode: 0
inWeight: 0.04742196
outWeight: 0.7060206
- serializedVersion: 3
time: 0.9874756
value: 0.0009422302
inSlope: 0.25219154
outSlope: 0.25219154
tangentMode: 0
weightedMode: 0
inWeight: 0.49323896
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 1
m_RotationOrder: 4
Pitch: 0
Yaw: 0
BodyYaw: 0
@ -4299,6 +4336,7 @@ MonoBehaviour:
serializedVersion: 2
m_Bits: 256
ShowGroundCast: 0
ShowMoveVector: 0
--- !u!114 &208949204
MonoBehaviour:
m_ObjectHideFlags: 0
@ -5051,7 +5089,7 @@ MeshRenderer:
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: cdcad3a2db55a61479d7f9d66bbcc2a8, type: 2}
- {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
@ -5210,6 +5248,37 @@ Transform:
m_Father: {fileID: 187747573}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &539510583
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 539510584}
m_Layer: 0
m_Name: GunRoot
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &539510584
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 539510583}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 583159968}
m_Father: {fileID: 2018729188}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &560908279
GameObject:
m_ObjectHideFlags: 0
@ -5569,16 +5638,16 @@ Transform:
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 583159967}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: -0.2, z: 0.4}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -0.19999993, z: 0.4}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 704117919}
- {fileID: 855764655}
- {fileID: 48849233}
- {fileID: 185162300}
m_Father: {fileID: 2018729188}
m_RootOrder: 1
m_Father: {fileID: 539510584}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &590506766
GameObject:
@ -19277,7 +19346,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1990215137}
- {fileID: 583159968}
- {fileID: 539510584}
m_Father: {fileID: 208949200}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}

View File

@ -13,6 +13,13 @@ namespace NeonTea.Quakeball.Player {
public MoveStyle CrouchingMoveStyle;
public Transform Head;
public Transform Body;
public Transform Gun;
[Header("Gun bobbing")]
public Vector3 GunBobFrom;
public Vector3 GunBobTo;
public float GunBobFrequency;
public AnimationCurve GunBobCurve;
[Header("Player rotation status")]
/// <summary>The pitch of the player's head.</summary>
@ -52,6 +59,7 @@ namespace NeonTea.Quakeball.Player {
[Header("Debug settings")]
public bool ShowGroundCast;
public bool ShowMoveVector;
private CharacterController CharacterController;
private Vector3 FeetPosition;
@ -84,6 +92,8 @@ namespace NeonTea.Quakeball.Player {
}
Body.localRotation = Quaternion.Lerp(Body.localRotation, Quaternion.Euler(0, BodyYaw, 0), 20f * Time.deltaTime);
Head.localRotation = Quaternion.Lerp(Head.localRotation, Quaternion.Euler(Pitch, Yaw - BodyYaw, 0), 15f * Time.deltaTime);
Vector3 GunTargetPosition = Vector3.Lerp(GunBobFrom, GunBobTo, GunBobCurve.Evaluate(Time.time * GunBobFrequency));
Gun.localPosition = Vector3.Lerp(Gun.localPosition, GunTargetPosition * GroundVelocity.magnitude / MoveStyle.TargetVelocity, 20f * Time.deltaTime);
UpdateMovement();
}
@ -123,10 +133,18 @@ namespace NeonTea.Quakeball.Player {
Acceleration = Mathf.Min(Acceleration, MoveStyle.TargetVelocity - CurrentSpeed);
GroundVelocity += FixedHeading * Acceleration;
CharacterController.Move((GroundVelocity + GravitationalVelocity) * Time.deltaTime);
Vector3 FinalMoveVector = GroundVelocity + GravitationalVelocity;
CharacterController.Move(FinalMoveVector * Time.deltaTime);
if (CharacterController.isGrounded) {
GroundedTime = Time.time;
}
if (ShowMoveVector) {
Debug.DrawLine(
transform.position + CharacterController.center,
transform.position + CharacterController.center + FinalMoveVector,
Color.green, 1.0f
);
}
}
}
}

View File

@ -18,6 +18,11 @@
"key": "log.path",
"value": "{\"m_Value\":\"ProBuilderLog.txt\"}"
},
{
"type": "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "VertexColorPalette.previousColorPalette",
"value": "{\"m_Value\":\"Assets/ProBuilder Data/Default Color Palette.asset\"}"
},
{
"type": "UnityEngine.ProBuilder.SemVer, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "about.identifier",
@ -32,6 +37,56 @@
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "lightmapping.autoUnwrapLightmapUV",
"value": "{\"m_Value\":true}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "editor.backFaceSelectEnabled",
"value": "{\"m_Value\":false}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "editor.toolbarIconGUI",
"value": "{\"m_Value\":false}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "editor.showSceneInfo",
"value": "{\"m_Value\":false}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "editor.autoRecalculateCollisions",
"value": "{\"m_Value\":false}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "editor.showEditorNotifications",
"value": "{\"m_Value\":false}"
},
{
"type": "System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "UVEditor.showPreviewMaterial",
"value": "{\"m_Value\":true}"
},
{
"type": "UnityEngine.ProBuilder.SelectionModifierBehavior, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "editor.rectSelectModifier",
"value": "{\"m_Value\":2}"
},
{
"type": "UnityEngine.ProBuilder.RectSelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "editor.dragSelectRectMode",
"value": "{\"m_Value\":0}"
},
{
"type": "UnityEngine.ProBuilder.SelectMode, Unity.ProBuilder, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null",
"key": "editor.selectMode",
"value": "{\"m_Value\":8}"
},
{
"type": "System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089",
"key": "uv.uvEditorGridSnapIncrement",
"value": "{\"m_Value\":0.125}"
}
]
}