add tracers

master
Jordan Orelli 4 years ago
parent 374cdfc0b5
commit 63360b4dd3

@ -48,9 +48,17 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
jumpHeight: 4
maxForwardJumpBoost: 2.5
timeToJumpApex: 0.4
moveSpeed: 6
maxFallSpeed: -20
timeToMaxRunSpeed: 0.15
timeToMaxAirmoveSpeed: 0.025
maxApexTime: 0.05
coyoteTime: 0.1
tracerPrefab: {fileID: 2438817463505096557, guid: 76ce4ec4aba832343abb5a3c19e66b7c,
type: 3}
jumpState: 0
--- !u!114 &4623847142764859892
MonoBehaviour:
m_ObjectHideFlags: 0

@ -0,0 +1,45 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2438817463505096557
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 113825385567799459}
- component: {fileID: 2852536200463660799}
m_Layer: 0
m_Name: Tracer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &113825385567799459
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2438817463505096557}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 76.46941, y: 2.8435178, z: -56.674828}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2852536200463660799
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2438817463505096557}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e6bf02804b7b40643bdf7adee8ada34d, type: 3}
m_Name:
m_EditorClassIdentifier:

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 76ce4ec4aba832343abb5a3c19e66b7c
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

@ -6829,7 +6829,7 @@ PrefabInstance:
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: timeToJumpApex
value: 0.25
value: 0.3
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
@ -6839,7 +6839,7 @@ PrefabInstance:
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: floatTime
value: 0.2
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
@ -6856,5 +6856,15 @@ PrefabInstance:
propertyPath: jumpState
value: 5
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: maxApexTime
value: 0.1
objectReference: {fileID: 0}
- target: {fileID: 4623847142764859891, guid: b29a944aaba25f643afdc6b049845662,
type: 3}
propertyPath: maxForwardJumpBoost
value: 2
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: b29a944aaba25f643afdc6b049845662, type: 3}

@ -6,19 +6,21 @@ using UnityEngine;
[RequireComponent(typeof(BoxCollider2D))]
public class PlayerController : MonoBehaviour {
public float jumpHeight = 4f;
public float jumpHorizontalScaling = 1.50f;
public float maxForwardJumpBoost = 2.50f;
public float timeToJumpApex = 0.4f;
public float moveSpeed = 6f;
public float maxFallSpeed = -20f;
public float timeToMaxRunSpeed = 0.15f;
public float timeToMaxAirmoveSpeed = 0.025f;
public float floatTime = 0.05f; // amount of time spent at max jump height before falling again
public float maxApexTime = 0.05f; // amount of time spent at max jump height before falling again
public float coyoteTime = 0.1f;
public GameObject tracerPrefab;
// this has to be public to be readable by the display, which is a code
// smell.
public JumpState jumpState;
private float jumpStateStart;
private float apexTime;
private float jumpVelocity = 8f;
private float gravity = -20f;
@ -34,6 +36,8 @@ public class PlayerController : MonoBehaviour {
}
void Update() {
Instantiate(tracerPrefab, transform.position, Quaternion.identity);
Vector2 input = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
float targetX = input.x * moveSpeed;
if (Mathf.Abs(input.x) < 0.1) {
@ -52,15 +56,15 @@ public class PlayerController : MonoBehaviour {
switch (jumpState) {
case JumpState.Grounded:
if (Input.GetButtonDown("Jump")) {
setJumpState(JumpState.Ascending);
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*jumpHorizontalScaling;
velocity.x = moveSpeed*maxForwardJumpBoost;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*jumpHorizontalScaling;
velocity.x = -moveSpeed*maxForwardJumpBoost;
} else {
velocity.x = 0f;
}
setJumpState(JumpState.Ascending);
} else {
velocity.y = gravity * Time.deltaTime;
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxRunSpeed);
@ -68,59 +72,51 @@ public class PlayerController : MonoBehaviour {
break;
case JumpState.Ascending:
// when ascending, you can alter your forward momentum, but you can't turn around.
float n = Mathf.InverseLerp(0, timeToJumpApex, Time.time - jumpStateStart);
float dragCoefficient = n * n;
if (Input.GetButton("Jump")) {
float jumpDrag = jumpVelocity * dragCoefficient;
if (n <= 0.4) {
jumpDrag = 0;
}
velocity.y = jumpVelocity - jumpDrag;
} else {
// if we're not pressing jump any more we add all the gravity
velocity.y += gravity * Time.deltaTime;
}
float forwardBoost = maxForwardJumpBoost - (maxForwardJumpBoost * dragCoefficient);
forwardBoost = Mathf.Clamp(forwardBoost, 1, maxForwardJumpBoost);
if (velocity.x >= 0) {
if (targetX >= 0) {
// continuing to move in your current direction is a boost
velocity.x = Mathf.SmoothDamp(velocity.x, targetX*jumpHorizontalScaling, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.SmoothDamp(velocity.x, targetX * forwardBoost, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
} else {
// moving in the opposite direction can slow you down but
// not turn you around
velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX, 0, velocity.x), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.Clamp(velocity.x, 0, initialVelocity.x);
}
} else {
if (targetX <= 0) {
// continuing to move in your current direction is a boost
velocity.x = Mathf.SmoothDamp(velocity.x, targetX*jumpHorizontalScaling, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.SmoothDamp(velocity.x, targetX * forwardBoost, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
} else {
// moving in the opposite direction can slow you down but
// not turn you around
velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX, velocity.x, 0), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.x = Mathf.Clamp(velocity.x, initialVelocity.x, 0);
}
}
float n = (Time.time - jumpStateStart) / timeToJumpApex;
n = Mathf.Clamp(n, 0, 1);
if (Input.GetButtonDown("Jump") && n >= 0.75f) {
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*jumpHorizontalScaling;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*jumpHorizontalScaling;
} else {
velocity.x = 0f;
}
setJumpState(JumpState.Ascending);
break;
}
if (Input.GetButton("Jump")) {
if (n < 0.4f) {
velocity.y = jumpVelocity;
} else {
velocity.y += gravity * Time.deltaTime * n * n;
}
} else {
velocity.y += gravity * Time.deltaTime;
}
// if we were rising in the last frame but will be falling in this
// frame, we should zero out the velocity to float instead.
if (initialVelocity.y >= 0 && velocity.y <= 0) {
velocity.y = 0;
setJumpState(JumpState.Apex);
apexTime = Mathf.Clamp(Time.time - jumpStateStart, 0, maxApexTime);
}
break;
@ -129,9 +125,9 @@ public class PlayerController : MonoBehaviour {
if (Input.GetButtonDown("Jump")) {
velocity.y = jumpVelocity;
if (input.x >= 0.25f) {
velocity.x = moveSpeed*jumpHorizontalScaling;
velocity.x = moveSpeed*maxForwardJumpBoost;
} else if (input.x <= -0.25f) {
velocity.x = -moveSpeed*jumpHorizontalScaling;
velocity.x = -moveSpeed*maxForwardJumpBoost;
} else {
velocity.x = 0f;
}
@ -139,10 +135,10 @@ public class PlayerController : MonoBehaviour {
} else {
// your horizontal motion at apex is constant throughout
// velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
float timeFloating = Time.time - jumpStateStart;
float floatTimeRemaining = floatTime - timeFloating;
if (floatTimeRemaining < 0) {
velocity.y += gravity * -floatTimeRemaining;
float timeAtApex = Time.time - jumpStateStart;
float apexTimeRemaining = maxApexTime - timeAtApex;
if (apexTimeRemaining < 0) {
velocity.y += gravity * -apexTimeRemaining;
setJumpState(JumpState.Descending);
} else {
velocity.y = 0;
@ -157,13 +153,13 @@ public class PlayerController : MonoBehaviour {
// horizontal travel is decreasing when descending, so that you
// always land vertically. Drag increases as you descend, so that it
// is 1 at the end of your descent.
float drag = n2*n2*moveSpeed;
if (velocity.x >= 0) {
velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX-drag, 0, 1f), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
} else {
velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX+drag, -1, 0), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
}
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
// float drag = n2*n2*Mathf.Abs(velocity.x);
// drag = 0;
// if (velocity.x >= 0) {
// velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX, 0, velocity.x-drag), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
// } else {
// velocity.x = Mathf.SmoothDamp(velocity.x, Mathf.Clamp(targetX, velocity.x+drag, 0), ref velocityXSmoothing, timeToMaxAirmoveSpeed);
// }
// fall speed is increasing when descending
velocity.y += gravity * Time.deltaTime * n2 * n2;
@ -184,17 +180,13 @@ public class PlayerController : MonoBehaviour {
}
break;
default:
case JumpState.Falling:
velocity.x = Mathf.SmoothDamp(velocity.x, targetX, ref velocityXSmoothing, timeToMaxAirmoveSpeed);
velocity.y += gravity * Time.deltaTime;
// if we were rising in the last frame but will be falling in this
// frame, we should zero out the velocity to float instead.
if (initialVelocity.y >= 0 && velocity.y <= 0) {
velocity.y = 0;
setJumpState(JumpState.Apex);
}
break;
default:
throw new System.Exception("bad jump state: " + jumpState);
}
if (velocity.y < maxFallSpeed) {

@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TracerDot : MonoBehaviour {
private float spawned;
void Start() {
spawned = Time.time;
}
void OnDrawGizmos() {
Gizmos.color = Color.red;
Gizmos.DrawWireSphere(transform.position, 0.125f);
}
void Update() {
if (Time.time - spawned > 2) {
Destroy(gameObject);
}
}
}

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e6bf02804b7b40643bdf7adee8ada34d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

@ -1,58 +1,63 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 12
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
m_DeferredReflections:
m_Mode: 1
m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
m_ScreenSpaceShadows:
m_Mode: 1
m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
m_LegacyDeferred:
m_Mode: 1
m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
m_DepthNormals:
m_Mode: 1
m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
m_MotionVectors:
m_Mode: 1
m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
m_LightHalo:
m_Mode: 1
m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
m_LensFlare:
m_Mode: 1
m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
m_AlwaysIncludedShaders:
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!30 &1
GraphicsSettings:
m_ObjectHideFlags: 0
serializedVersion: 13
m_Deferred:
m_Mode: 1
m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
m_DeferredReflections:
m_Mode: 1
m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
m_ScreenSpaceShadows:
m_Mode: 1
m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
m_LegacyDeferred:
m_Mode: 1
m_Shader: {fileID: 63, guid: 0000000000000000f000000000000000, type: 0}
m_DepthNormals:
m_Mode: 1
m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
m_MotionVectors:
m_Mode: 1
m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
m_LightHalo:
m_Mode: 1
m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
m_LensFlare:
m_Mode: 1
m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
m_AlwaysIncludedShaders:
- {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 0}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings: []
m_LightmapStripping: 0
m_FogStripping: 0
m_InstancingStripping: 0
m_LightmapKeepPlain: 1
m_LightmapKeepDirCombined: 1
m_LightmapKeepDynamicPlain: 1
m_LightmapKeepDynamicDirCombined: 1
m_LightmapKeepShadowMask: 1
m_LightmapKeepSubtractive: 1
m_FogKeepLinear: 1
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 0
- {fileID: 10783, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16000, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 16001, guid: 0000000000000000f000000000000000, type: 0}
- {fileID: 17000, guid: 0000000000000000f000000000000000, type: 0}
m_PreloadedShaders: []
m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000,
type: 0}
m_CustomRenderPipeline: {fileID: 0}
m_TransparencySortMode: 0
m_TransparencySortAxis: {x: 0, y: 0, z: 1}
m_DefaultRenderingPath: 1
m_DefaultMobileRenderingPath: 1
m_TierSettings: []
m_LightmapStripping: 0
m_FogStripping: 0
m_InstancingStripping: 0
m_LightmapKeepPlain: 1
m_LightmapKeepDirCombined: 1
m_LightmapKeepDynamicPlain: 1
m_LightmapKeepDynamicDirCombined: 1
m_LightmapKeepShadowMask: 1
m_LightmapKeepSubtractive: 1
m_FogKeepLinear: 1
m_FogKeepExp: 1
m_FogKeepExp2: 1
m_AlbedoSwatchInfos: []
m_LightsUseLinearIntensity: 0
m_LightsUseColorTemperature: 0
m_LogWhenShaderIsCompiled: 0
m_AllowEnlightenSupportForUpgradedProject: 1

@ -42,8 +42,8 @@ PlayerSettings:
m_SplashScreenLogos: []
m_VirtualRealitySplashScreen: {fileID: 0}
m_HolographicTrackingLossScreen: {fileID: 0}
defaultScreenWidth: 1024
defaultScreenHeight: 768
defaultScreenWidth: 1920
defaultScreenHeight: 1080
defaultScreenWidthWeb: 960
defaultScreenHeightWeb: 600
m_StereoRenderingPath: 0
@ -66,7 +66,7 @@ PlayerSettings:
androidRenderOutsideSafeArea: 0
androidUseSwappy: 0
androidBlitType: 0
defaultIsNativeResolution: 1
defaultIsNativeResolution: 0
macRetinaSupport: 1
runInBackground: 1
captureSingleScreen: 0
@ -80,7 +80,7 @@ PlayerSettings:
bakeCollisionMeshes: 0
forceSingleInstance: 0
useFlipModelSwapchain: 1
resizableWindow: 0
resizableWindow: 1
useMacAppStoreValidation: 0
macAppStoreCategory: public.app-category.games
gpuSkinning: 0
@ -90,8 +90,8 @@ PlayerSettings:
xboxEnableKinectAutoTracking: 0
xboxEnableFitness: 0
visibleInBackground: 1
allowFullscreenSwitch: 1
fullscreenMode: 1
allowFullscreenSwitch: 0
fullscreenMode: 3
xboxSpeechDB: 0
xboxEnableHeadOrientation: 0
xboxEnableGuest: 0
@ -114,11 +114,11 @@ PlayerSettings:
vulkanNumSwapchainBuffers: 3
vulkanEnableSetSRGBWrite: 0
m_SupportedAspectRatios:
4:3: 1
5:4: 1
16:10: 1
4:3: 0
5:4: 0
16:10: 0
16:9: 1
Others: 1
Others: 0
bundleVersion: 0.1
preloadedAssets: []
metroInputSource: 0
@ -563,8 +563,8 @@ PlayerSettings:
apiCompatibilityLevelPerPlatform: {}
m_RenderingPath: 1
m_MobileRenderingPath: 1
metroPackageName: Template_2D
metroPackageVersion:
metroPackageName: Template2D
metroPackageVersion: 1.0.0.0
metroCertificatePath:
metroCertificatePassword:
metroCertificateSubject:
@ -572,7 +572,7 @@ PlayerSettings:
metroCertificateNotAfter: 0000000000000000
metroApplicationDescription: Template_2D
wsaImages: {}
metroTileShortName:
metroTileShortName: Dungeon Baby
metroTileShowName: 0
metroMediumTileShowName: 0
metroLargeTileShowName: 0
@ -585,8 +585,54 @@ PlayerSettings:
metroSplashScreenBackgroundColor: {r: 0.12941177, g: 0.17254902, b: 0.21568628,
a: 1}
metroSplashScreenUseBackgroundColor: 0
platformCapabilities: {}
metroTargetDeviceFamilies: {}
platformCapabilities:
WindowsStoreApps:
AllJoyn: False
Appointments: False
BackgroundMediaPlayback: False
BlockedChatMessages: False
Bluetooth: False
Chat: False
CodeGeneration: False
Contacts: False
EnterpriseAuthentication: False
GazeInput: False
HumanInterfaceDevice: False
InputInjectionBrokered: False
InternetClient: False
InternetClientServer: False
Location: False
LowLevelDevices: False
Microphone: False
MusicLibrary: False
Objects3D: False
OfflineMapsManagement: False
PhoneCall: False
PhoneCallHistoryPublic: False
PicturesLibrary: False
PointOfService: False
PrivateNetworkClientServer: False
Proximity: False
RecordedCallsFolder: False
RemoteSystem: False
RemovableStorage: False
SharedUserCertificates: False
SpatialPerception: False
SystemManagement: False
UserAccountInformation: False
UserDataTasks: False
UserNotificationListener: False
VideosLibrary: False
VoipCall: False
WebCam: False
metroTargetDeviceFamilies:
Desktop: False
Holographic: False
IoT: False
IoTHeadless: False
Mobile: False
Team: False
Xbox: False
metroFTAName:
metroFTAFileTypes: []
metroProtocolName:

Loading…
Cancel
Save