-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterJumpController.cs
More file actions
117 lines (95 loc) · 3.95 KB
/
CharacterJumpController.cs
File metadata and controls
117 lines (95 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System;
using UnityEngine;
using ECM2;
using Duckov;
namespace MyJumpMod
{
public class CharacterJumpController : MonoBehaviour
{
private Character _character;
private CharacterMovement _characterMovement;
private Movement _movement;
[Header("점프 설정 (높이 및 가속)")]
public float jumpPower = 6.0f; // 순간 도약력
public float maxJumpHeight = 9.0f; // 상승 속도 제한
public float boostAccel = 5.0f; // 꾹 누를 때 추가 상승 힘
public float airControlFactor = 1.0f; // 공중 제어력
[Header("하강 설정 (묵직함 조절)")]
// [수정] 1.8f: 하강 중 중력을 약 1.8배로 체감하게 만듭니다.
// 더 빨리 떨어지고 싶다면 2.5f 정도로 높이세요.
public float fallGravityMultiplier = 2.2f;
private bool _isJumping = false;
private bool _isJumpingHeld = false;
private float _coyoteTimer = 0f;
public KeyCode jumpKey = KeyCode.Z;
private void Start()
{
_character = GetComponent<Character>();
_characterMovement = GetComponent<CharacterMovement>();
var mainControl = GetComponent<CharacterMainControl>();
if (mainControl != null) _movement = mainControl.movementControl;
Debug.Log("[MyJumpMod] 묵직한 하강 로직이 탑재된 연속 점프 가동!");
}
private void Update()
{
if (_characterMovement == null) return;
if (_characterMovement.isOnGround) _coyoteTimer = 0.15f;
else _coyoteTimer -= Time.deltaTime;
if (Input.GetKeyDown(jumpKey))
{
StartJumpSequence();
}
if (Input.GetKeyUp(jumpKey)) _isJumpingHeld = false;
if (_isJumping)
{
ApplyJumpPhysics();
}
}
private void StartJumpSequence()
{
_isJumping = true;
_isJumpingHeld = true;
// 지면 흡착 일시 정지 및 모드 전환
_characterMovement.PauseGroundConstraint(0.2f);
if (_character != null) _character.SetMovementMode(Character.MovementMode.Falling);
// 수직 속도 주입
Vector3 v = _characterMovement.velocity;
v.y = jumpPower;
_characterMovement.velocity = v;
Debug.Log("[MyJumpMod] 도약!");
}
private void ApplyJumpPhysics()
{
Vector3 v = _characterMovement.velocity;
// [상승 로직] 키를 꾹 누르고 있을 때 부드러운 가속
if (Input.GetKey(jumpKey) && _isJumpingHeld && v.y > 0)
{
v.y += boostAccel * Time.deltaTime;
v.y = Mathf.Min(v.y, maxJumpHeight);
}
// [하강 로직] 정점을 찍고 내려올 때 속도를 인위적으로 증가
// v.y < 0 이면 떨어지는 중입니다.
if (v.y < 0)
{
// 엔진 기본 중력을 더 강하게 끌어당기도록 보정값을 더해줍니다.
v.y += Physics.gravity.y * (fallGravityMultiplier - 1.0f) * Time.deltaTime;
}
// [공중 방향 제어]
if (_movement != null)
{
Vector3 moveInput = _movement.MoveInput;
if (moveInput.magnitude > 0.02f)
{
float speed = _movement.Running ? _movement.runSpeed : _movement.walkSpeed;
v.x = Mathf.Lerp(v.x, moveInput.x * speed, Time.deltaTime * 5f);
v.z = Mathf.Lerp(v.z, moveInput.z * speed, Time.deltaTime * 5f);
}
}
_characterMovement.velocity = v;
if (_characterMovement.isOnGround && v.y <= 0.1f)
{
_isJumping = false;
}
}
}
}