Rework movement system to not directly write velocity

This commit is contained in:
2024-10-22 00:02:11 -07:00
parent f2912e3d53
commit 0c64c8dafc
2 changed files with 18 additions and 7 deletions

View File

@@ -241,7 +241,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: -4152331571693237436, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: m_LinearDamping
value: 0
value: 15
objectReference: {fileID: 0}
- target: {fileID: -4152331571693237436, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: m_CollisionDetection
@@ -315,6 +315,10 @@ PrefabInstance:
propertyPath: m_RenderPostProcessing
value: 0
objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: dashDistance
value: 1000
objectReference: {fileID: 0}
- target: {fileID: 6118034672792182209, guid: e05928a0d673caf999d31b31b994a112, type: 3}
propertyPath: attackCooldownSeconds
value: 3

View File

@@ -25,10 +25,10 @@ public class Teo : MonoBehaviour
// Update is called once per frame
void Update() {
// Move player
controller.linearVelocity = new Vector2 (
controller.AddRelativeForce (new Vector2 (
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
).normalized * moveSpeed + dashVelocity;
).normalized * moveSpeed);
// Attack on click if not on cooldown
if (Input.GetMouseButtonDown(0)) {
Attack();
@@ -60,11 +60,18 @@ public class Teo : MonoBehaviour
}
void Dash() {
if (Time.fixedTime-lastDashTime < dashCooldownSeconds) return;
BoxCollider2D collider = GetComponent<BoxCollider2D>();
lastDashTime = Time.fixedTime;
transform.position += new Vector3(
collider.enabled = false;
controller.linearDamping = 0;
controller.AddRelativeForce (new Vector2(
Input.mousePosition.x - Screen.width/2,
Input.mousePosition.y - Screen.height/2,
0
).normalized * dashDistance;
Input.mousePosition.y - Screen.height/2
).normalized * dashDistance);
Debug.Log("before");
new WaitForSeconds(2F);
Debug.Log("after");
controller.linearDamping = 15;
collider.enabled = true;
}
}