Changes
Page history
Update Night of Horror
authored
Nov 25, 2024
by
Hong, Xin
Hide whitespace changes
Inline
Side-by-side
home.md
View page @
4f581f22
...
...
@@ -3,6 +3,7 @@ title: Night of Horror
---
[Toc]
# Game Design Document
...
...
@@ -149,88 +150,45 @@ public class PlayerInput : MonoBehaviour
}
```
```
csharp
using
System
;
using
System.Collections
;
using
System.Collections.Generic
;
using
UnityEngine
;
public
class
PlayerMovingState
:
PlayerState
private
void
ResetCameraRotation
()
{
protected
Vector2
movementInput
;
Vector3
cameraForward
=
stateMachine
.
Player
.
cameraTransform
.
forward
;
cameraForward
.
y
=
0
;
cameraForward
.
Normalize
();
protected
float
movementSpeed
=
3f
;
public
PlayerMovingState
(
PlayerStateMachine
playerStateMachine
)
:
base
(
playerStateMachine
)
{
}
public
override
void
Enter
()
{
base
.
Enter
();
Quaternion
rotation
=
Quaternion
.
LookRotation
(
cameraForward
);
ResetCameraRotation
();
}
public
override
void
Update
()
{
base
.
Update
();
stateMachine
.
Player
.
playerRigidbody
.
rotation
=
rotation
;
}
MovementInput
();
}
private
void
MovementInput
()
{
movementInput
=
stateMachine
.
Player
.
input
.
playerActions
.
Movement
.
ReadValue
<
Vector2
>();
}
public
override
void
PhysicsUpdate
()
{
base
.
PhysicsUpdate
();
private
void
Move
()
{
Vector3
cameraForward
=
stateMachine
.
Player
.
cameraTransform
.
forward
;
cameraForward
.
y
=
0
;
cameraForward
.
Normalize
();
Move
();
}
Vector3
cameraRight
=
stateMachine
.
Player
.
cameraTransform
.
right
;
cameraRight
.
y
=
0
;
cameraRight
.
Normalize
();
public
override
void
Exit
()
{
base
.
Exit
();
}
Vector3
moveDirection
=
cameraForward
*
movementInput
.
y
+
cameraRight
*
movementInput
.
x
;
private
void
ResetCameraRotation
(
)
if
(
moveDirection
!=
Vector3
.
zero
)
{
Vector3
cameraForward
=
stateMachine
.
Player
.
cameraTransform
.
forward
;
cameraForward
.
y
=
0
;
cameraForward
.
Normalize
();
Quaternion
rotation
=
Quaternion
.
LookRotation
(
cameraForward
);
Quaternion
targetRotation
=
Quaternion
.
LookRotation
(
moveDirection
);
float
rotationSpeed
=
0.5f
;
stateMachine
.
Player
.
playerRigidbody
.
rotation
=
Quaternion
.
Slerp
(
stateMachine
.
Player
.
playerRigidbody
.
rotation
,
targetRotation
,
rotationSpeed
*
Time
.
deltaTime
);
stateMachine
.
Player
.
playerRigidbody
.
rotation
=
rotation
;
stateMachine
.
Player
.
playerRigidbody
.
velocity
=
moveDirection
.
normalized
*
movementSpeed
;
}
private
void
MovementInput
()
{
movementInput
=
stateMachine
.
Player
.
input
.
playerActions
.
Movement
.
ReadValue
<
Vector2
>();
}
private
void
Move
()
else
{
Vector3
cameraForward
=
stateMachine
.
Player
.
cameraTransform
.
forward
;
cameraForward
.
y
=
0
;
cameraForward
.
Normalize
();
Vector3
cameraRight
=
stateMachine
.
Player
.
cameraTransform
.
right
;
cameraRight
.
y
=
0
;
cameraRight
.
Normalize
();
Vector3
moveDirection
=
cameraForward
*
movementInput
.
y
+
cameraRight
*
movementInput
.
x
;
if
(
moveDirection
!=
Vector3
.
zero
)
{
Quaternion
targetRotation
=
Quaternion
.
LookRotation
(
moveDirection
);
float
rotationSpeed
=
0.5f
;
stateMachine
.
Player
.
playerRigidbody
.
rotation
=
Quaternion
.
Slerp
(
stateMachine
.
Player
.
playerRigidbody
.
rotation
,
targetRotation
,
rotationSpeed
*
Time
.
deltaTime
);
stateMachine
.
Player
.
playerRigidbody
.
velocity
=
moveDirection
.
normalized
*
movementSpeed
;
}
else
{
stateMachine
.
Player
.
playerRigidbody
.
velocity
=
Vector3
.
zero
;
}
stateMachine
.
Player
.
playerRigidbody
.
velocity
=
Vector3
.
zero
;
}
}
```
...
...
...
...