movement acceleration

master
Jordan Orelli 5 years ago
parent 401db24db9
commit a3dacc27f8

@ -9,10 +9,10 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 4623847142764859880}
- component: {fileID: 4623847142764859891}
- component: {fileID: 4623847142764859892}
- component: {fileID: 4623847142764859895}
- component: {fileID: 4623847142764859894}
- component: {fileID: 4623847142764859892}
- component: {fileID: 4623847142764859891}
- component: {fileID: 4623847142764859893}
m_Layer: 8
m_Name: Player
@ -35,6 +35,39 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &4623847142764859891
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4623847142764859890}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e86ea0dadc883746820f81edbde5cab, type: 3}
m_Name:
m_EditorClassIdentifier:
jumpHeight: 4
timeToJumpApex: 0.4
moveSpeed: 6
maxFallSpeed: -20
--- !u!114 &4623847142764859892
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4623847142764859890}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b21a38e98a85794b9312e3ac293ad9f, type: 3}
m_Name:
m_EditorClassIdentifier:
horizontalRayCount: 4
verticalRayCount: 4
collisionMask:
serializedVersion: 2
m_Bits: 1024
--- !u!33 &4623847142764859895
MeshFilter:
m_ObjectHideFlags: 0
@ -82,33 +115,6 @@ MeshRenderer:
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!114 &4623847142764859892
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4623847142764859890}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5b21a38e98a85794b9312e3ac293ad9f, type: 3}
m_Name:
m_EditorClassIdentifier:
horizontalRayCount: 4
verticalRayCount: 4
--- !u!114 &4623847142764859891
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4623847142764859890}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6e86ea0dadc883746820f81edbde5cab, type: 3}
m_Name:
m_EditorClassIdentifier:
gravity: -20
--- !u!61 &4623847142764859893
BoxCollider2D:
m_ObjectHideFlags: 0

@ -310,6 +310,112 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0}
--- !u!1 &1934386708
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1934386709}
- component: {fileID: 1934386712}
- component: {fileID: 1934386711}
- component: {fileID: 1934386710}
m_Layer: 10
m_Name: Quad (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1934386709
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1934386708}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 2.46, y: -2.79, z: 0}
m_LocalScale: {x: 1.1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 2094910951}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!61 &1934386710
BoxCollider2D:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1934386708}
m_Enabled: 1
m_Density: 1
m_Material: {fileID: 0}
m_IsTrigger: 0
m_UsedByEffector: 0
m_UsedByComposite: 0
m_Offset: {x: 0, y: 0}
m_SpriteTilingProperty:
border: {x: 0, y: 0, z: 0, w: 0}
pivot: {x: 0, y: 0}
oldSize: {x: 0, y: 0}
newSize: {x: 0, y: 0}
adaptiveTilingThreshold: 0
drawMode: 0
adaptiveTiling: 0
m_AutoTiling: 0
serializedVersion: 2
m_Size: {x: 1, y: 1}
m_EdgeRadius: 0
--- !u!23 &1934386711
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1934386708}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 2100000, guid: 8df84f2be8e3fce49ac07c94333dc383, type: 2}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
--- !u!33 &1934386712
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1934386708}
m_Mesh: {fileID: 10210, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &1959391869
GameObject:
m_ObjectHideFlags: 0
@ -444,6 +550,7 @@ Transform:
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:
- {fileID: 1959391870}
- {fileID: 1934386709}
m_Father: {fileID: 0}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -514,6 +621,16 @@ PrefabInstance:
propertyPath: m_Name
value: Player
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: timeToJumpApex
value: 0.97
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: maxFallSpeed
value: -20
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859892, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: collisionMask.m_Bits

@ -8,11 +8,15 @@ public class PlayerController : MonoBehaviour {
public float jumpHeight = 4f;
public float timeToJumpApex = 0.4f;
public float moveSpeed = 6f;
public float maxFallSpeed = -20f;
public float timeToMaxRunSpeed = 0.15f;
public float timeToMaxAirmoveSpeed = 0.25f;
private float jumpVelocity = 8f;
private float gravity = -20f;
private Vector3 velocity;
private MoveController moveController;
private float velocityXSmoothing;
void Start() {
moveController = GetComponent<MoveController>();
@ -32,8 +36,18 @@ public class PlayerController : MonoBehaviour {
if (Input.GetKeyDown(KeyCode.Space) && moveController.collisions.below) {
velocity.y = jumpVelocity;
}
velocity.x = input.x * moveSpeed;
float targetX = input.x * moveSpeed;
if (moveController.collisions.below) {
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
} else {
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
}
velocity.y += gravity * Time.deltaTime;
if (velocity.y < maxFallSpeed) {
velocity.y = maxFallSpeed;
}
moveController.Move(velocity * Time.deltaTime);
}

Loading…
Cancel
Save