Added air jumps

This commit is contained in:
Jeremy Smitherman 2026-04-25 00:15:37 -05:00
parent 7e1e897405
commit 47956bdc6e
8 changed files with 1927 additions and 43 deletions

View File

@ -6,13 +6,10 @@
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="60468364-7d9c-427f-83f9-f6cd83ef8783" name="Changes" comment=""> <list default="true" id="60468364-7d9c-427f-83f9-f6cd83ef8783" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.SpringJam2026/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Audio/Mixer.mixer" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Audio/Mixer.mixer" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/Prefabs/Spring/Idle.anim" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Prefabs/Spring/Idle.anim" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/InputSystem_Actions.inputactions" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/InputSystem_Actions.inputactions" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/Prefabs/Spring/Spring.anim" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Prefabs/Spring/Spring.anim" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Bootstrap.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scenes/Bootstrap.unity" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scenes/Game.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scenes/Game.unity" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/Scenes/Game.unity" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scenes/Game.unity" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Scripts/Player/Movement.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player/Movement.cs" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/Scripts/Player/Movement.cs" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Scripts/Player/Movement.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/Tilemaps/background.png.meta" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Tilemaps/background.png.meta" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/UI Toolkit/PanelSettings.asset" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/UI Toolkit/PanelSettings.asset" afterDir="false" />
<change beforePath="$PROJECT_DIR$/ProjectSettings/TagManager.asset" beforeDir="false" afterPath="$PROJECT_DIR$/ProjectSettings/TagManager.asset" afterDir="false" /> <change beforePath="$PROJECT_DIR$/ProjectSettings/TagManager.asset" beforeDir="false" afterPath="$PROJECT_DIR$/ProjectSettings/TagManager.asset" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -126,7 +123,7 @@
<option name="number" value="Default" /> <option name="number" value="Default" />
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1777050991106</updated> <updated>1777050991106</updated>
<workItem from="1777050993247" duration="13198000" /> <workItem from="1777050993247" duration="19210000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -55,7 +55,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

View File

@ -70,7 +70,7 @@ AnimationClip:
m_Level: 0 m_Level: 0
m_CycleOffset: 0 m_CycleOffset: 0
m_HasAdditiveReferencePose: 0 m_HasAdditiveReferencePose: 0
m_LoopTime: 1 m_LoopTime: 0
m_LoopBlend: 0 m_LoopBlend: 0
m_LoopBlendOrientation: 0 m_LoopBlendOrientation: 0
m_LoopBlendPositionY: 0 m_LoopBlendPositionY: 0

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Management;
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
@ -8,18 +9,29 @@ namespace Player
[RequireComponent(typeof(Rigidbody2D))] [RequireComponent(typeof(Rigidbody2D))]
public class Movement : MonoBehaviour public class Movement : MonoBehaviour
{ {
private static readonly int Spring = Animator.StringToHash("spring");
[SerializeField] private float runSpeed; [SerializeField] private float runSpeed;
[SerializeField] private float springPower; [SerializeField] private float springPower;
[SerializeField] private float jumpForce;
[SerializeField] private float airJumpForce;
[SerializeField] private SpriteRenderer spriteRenderer; [SerializeField] private SpriteRenderer spriteRenderer;
[SerializeField] private float turnDelay; [SerializeField] private float turnDelay;
[SerializeField] private InputActionReference interactReference; [SerializeField] private InputActionReference interactReference;
private bool _onSpring; private Animator _springAnimator;
private Rigidbody2D _rb; private Rigidbody2D _rb;
private bool _grounded = true; private bool _grounded = true;
private bool _facingLeft; private bool _facingLeft;
private float _turnDelayTimer; private float _turnDelayTimer;
private float _groundedCheckTimer;
private bool _interact; private bool _interact;
private int _airJumpCharges;
private bool _jumpPressedThisFrame = true;
private bool _fireSpring;
private bool _jump;
private bool _airJump;
private Vector2 _airJumpDir;
private bool _autoDrive = true;
private void Awake() private void Awake()
{ {
@ -30,28 +42,81 @@ namespace Player
interactReference.action.canceled += HandleInteraction; interactReference.action.canceled += HandleInteraction;
} }
private void Start()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}
private void HandleInteraction(InputAction.CallbackContext obj) private void HandleInteraction(InputAction.CallbackContext obj)
{ {
_interact = obj.ReadValueAsButton(); _interact = obj.ReadValueAsButton();
_jumpPressedThisFrame = _interact;
} }
private void Update() private void Update()
{ {
Vector2 mouseScreenPos = Mouse.current.position.ReadValue();
Vector3 mouseWorldPos = Camera.main.ScreenToWorldPoint(
new Vector3(mouseScreenPos.x, mouseScreenPos.y, -Camera.main.transform.position.z)
);
_airJumpDir = ((Vector2)mouseWorldPos - (Vector2)transform.position).normalized;
_groundedCheckTimer += Time.deltaTime;
_turnDelayTimer += Time.deltaTime; _turnDelayTimer += Time.deltaTime;
spriteRenderer.flipX = !_facingLeft; spriteRenderer.flipX = !_facingLeft;
Debug.Log($"{_onSpring} {_interact}"); if (_springAnimator && _jumpPressedThisFrame)
if (_onSpring && _interact)
{ {
_onSpring = false; _groundedCheckTimer = 0f;
_springAnimator.SetTrigger(Spring);
_springAnimator = null;
_grounded = false; _grounded = false;
_rb.linearVelocityX = 0; _fireSpring = true;
_rb.AddForce(Vector2.up * springPower, ForceMode2D.Impulse); _autoDrive = false;
} }
if (_grounded && _jumpPressedThisFrame)
{
_grounded = false;
_groundedCheckTimer = 0f;
_jump = true;
_jumpPressedThisFrame = false;
}
if (!_grounded && _airJumpCharges > 0 && _jumpPressedThisFrame)
{
Debug.Log(_airJumpDir);
_airJump = true;
}
_jumpPressedThisFrame = false;
} }
private void FixedUpdate() private void FixedUpdate()
{ {
if (_grounded) if (_jump)
{
_jump = false;
_grounded = false;
_rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
if (_airJump)
{
_airJump = false;
_airJumpCharges--;
_rb.AddForce(_airJumpDir * airJumpForce, ForceMode2D.Impulse);
}
if (_fireSpring)
{
_fireSpring = false;
_rb.linearVelocityX = 0;
_rb.AddForce(Vector2.up * springPower, ForceMode2D.Impulse);
}
if (_autoDrive)
{ {
_rb.linearVelocityX = _facingLeft ? -runSpeed : runSpeed; _rb.linearVelocityX = _facingLeft ? -runSpeed : runSpeed;
} }
@ -60,33 +125,66 @@ namespace Player
private void OnTriggerEnter2D(Collider2D other) private void OnTriggerEnter2D(Collider2D other)
{ {
if (other.gameObject.layer == LayerMask.NameToLayer("Spring")) if (other.gameObject.layer == LayerMask.NameToLayer("Spring"))
_onSpring = true; _springAnimator = other.gameObject.GetComponent<Animator>();
if (other.gameObject.layer == LayerMask.NameToLayer("Pickup"))
{
_airJumpCharges++;
Destroy(other.gameObject);
}
} }
private void OnTriggerExit2D(Collider2D other) private void OnTriggerExit2D(Collider2D other)
{ {
if (other.gameObject.layer == LayerMask.NameToLayer("Spring")) if (other.gameObject.layer == LayerMask.NameToLayer("Spring"))
{ {
_onSpring = false; _springAnimator = null;
} }
} }
private void OnCollisionEnter2D(Collision2D other)
{
CheckCollisions(other);
}
private void OnCollisionStay2D(Collision2D other) private void OnCollisionStay2D(Collision2D other)
{ {
if (_turnDelayTimer < turnDelay) return; CheckCollisions(other);
if (other.gameObject.layer == LayerMask.NameToLayer("Spring")) return; }
private void CheckCollisions(Collision2D other)
{
var contacts = new List<ContactPoint2D>(); var contacts = new List<ContactPoint2D>();
other.GetContacts(contacts); other.GetContacts(contacts);
foreach(var c in contacts) if (_turnDelayTimer >= turnDelay &&
other.gameObject.layer != LayerMask.NameToLayer("Spring") &&
other.gameObject.layer != LayerMask.NameToLayer("Pickup"))
{
foreach (var c in contacts)
{ {
var x = c.normal.x; var x = c.normal.x;
if (Mathf.Abs(x) > 0.1f) if (Mathf.Abs(x) > 0.1f)
{ {
_facingLeft = !_facingLeft; _facingLeft = !_facingLeft;
_turnDelayTimer = 0f; _turnDelayTimer = 0f;
break;
}
}
}
_grounded = false;
if (_groundedCheckTimer > turnDelay)
{
foreach (var c in contacts)
{
var y = c.normal.y;
_grounded = Mathf.Approximately(1f, y);
if (_grounded)
{
_autoDrive = true;
return; return;
} }
} }
} }
} }
}
} }

BIN
Assets/Tilemaps/fruit.png (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,143 @@
fileFormatVersion: 2
guid: 8832522912916174da6762a3f507e424
TextureImporter:
internalIDToNameTable:
- first:
213: -5321949957799140045
second: fruit_0
externalObjects: {}
serializedVersion: 13
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMipmapLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 0
aniso: 1
mipBias: 0
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 2
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 16
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 4
buildTarget: DefaultTexturePlatform
maxTextureSize: 32
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 4
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
ignorePlatformSupport: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites:
- serializedVersion: 2
name: fruit_0
rect:
serializedVersion: 2
x: 0
y: 0
width: 11
height: 13
alignment: 0
pivot: {x: 0, y: 0}
border: {x: 0, y: 0, z: 0, w: 0}
customData:
outline: []
physicsShape: []
tessellationDetail: -1
bones: []
spriteID: 3352af4d5b2a426b0800000000000000
internalID: -5321949957799140045
vertices: []
indices:
edges: []
weights: []
outline: []
customData:
physicsShape: []
bones: []
spriteID:
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spriteCustomMetadata:
entries: []
nameFileIdTable:
fruit_0: -5321949957799140045
mipmapLimitGroupName:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View File

@ -11,7 +11,7 @@ TagManager:
- Spring - Spring
- Water - Water
- UI - UI
- - Pickup
- -
- -
- -