Merge branch 'devVlad' into HelmetVersion
This commit is contained in:
commit
c39c45a625
@ -675,8 +675,17 @@ LineRenderer:
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
@ -1130,8 +1139,17 @@ LineRenderer:
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0.33333334
|
||||
outWeight: 0.33333334
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
- serializedVersion: 3
|
||||
time: 1
|
||||
value: 1
|
||||
inSlope: 0
|
||||
outSlope: 0
|
||||
tangentMode: 0
|
||||
weightedMode: 0
|
||||
inWeight: 0
|
||||
outWeight: 0
|
||||
m_PreInfinity: 2
|
||||
m_PostInfinity: 2
|
||||
m_RotationOrder: 4
|
||||
@ -1873,6 +1891,7 @@ GameObject:
|
||||
- component: {fileID: 7338634134653167399}
|
||||
- component: {fileID: 6816638489069482198}
|
||||
- component: {fileID: 5964534008193362612}
|
||||
- component: {fileID: 3203601341080865406}
|
||||
m_Layer: 0
|
||||
m_Name: XR Origin (XR Rig)
|
||||
m_TagString: Player
|
||||
@ -1995,7 +2014,7 @@ MonoBehaviour:
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
m_System: {fileID: 6816638489069482198}
|
||||
m_MoveSpeed: 5
|
||||
m_MoveSpeed: 2
|
||||
m_EnableStrafe: 1
|
||||
m_EnableFly: 0
|
||||
m_UseGravity: 1
|
||||
@ -2025,6 +2044,41 @@ MonoBehaviour:
|
||||
m_SingletonActionBindings: []
|
||||
m_Flags: 0
|
||||
m_Reference: {fileID: -8198699208435500284, guid: c348712bda248c246b8c49b3db54643f, type: 3}
|
||||
--- !u!114 &3203601341080865406
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 7147664097568639172}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 2d54964b90d6903429f3430ea2ab1f61, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
LeftHand: {fileID: 2067026960446241885}
|
||||
RightHand: {fileID: 3870153961956791389}
|
||||
MainCamera: {fileID: 4098506887931384771}
|
||||
_MoveProvider: {fileID: 5964534008193362612}
|
||||
PositionPreviousFrameLeftHand: {x: 0, y: 0, z: 0}
|
||||
PositionPreviousFrameRightHand: {x: 0, y: 0, z: 0}
|
||||
PlayerPositionPreviousFrame: {x: 0, y: 0, z: 0}
|
||||
PlayerPositionCurrentFrame: {x: 0, y: 0, z: 0}
|
||||
PositionCurrentFrameLeftHand: {x: 0, y: 0, z: 0}
|
||||
PositionCurrentFrameRightHand: {x: 0, y: 0, z: 0}
|
||||
BaseSpeed: 0
|
||||
SprintSpeedMultiplier: 8
|
||||
HandSpeedThreshold: 0.02
|
||||
HandSpeed: 0
|
||||
MaxStamina: 2
|
||||
Stamina: 0
|
||||
StaminaDrainRate: 2
|
||||
StaminaRecoveryRate: 0.5
|
||||
LowStaminaMultiplier: 0.125
|
||||
StaminaRecoveryDelay: 4
|
||||
IsRecovering: 0
|
||||
RecoveryTimer: 0
|
||||
IsPreRecovery: 0
|
||||
--- !u!1 &9084633494757648245
|
||||
GameObject:
|
||||
m_ObjectHideFlags: 0
|
||||
|
127
Assets/Crossy Road VR/SwingingArmMotionScript.cs
Normal file
127
Assets/Crossy Road VR/SwingingArmMotionScript.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class SwingingArmMotionScript : MonoBehaviour
|
||||
{
|
||||
// Game Objects
|
||||
[SerializeField] private GameObject LeftHand;
|
||||
[SerializeField] private GameObject RightHand;
|
||||
[SerializeField] private GameObject MainCamera;
|
||||
[SerializeField] private ActionBasedContinuousMoveProvider _MoveProvider;
|
||||
|
||||
// Vector3 Positions
|
||||
[SerializeField] private Vector3 PositionPreviousFrameLeftHand;
|
||||
[SerializeField] private Vector3 PositionPreviousFrameRightHand;
|
||||
[SerializeField] private Vector3 PlayerPositionPreviousFrame;
|
||||
[SerializeField] private Vector3 PlayerPositionCurrentFrame;
|
||||
[SerializeField] private Vector3 PositionCurrentFrameLeftHand;
|
||||
[SerializeField] private Vector3 PositionCurrentFrameRightHand;
|
||||
|
||||
// Speed
|
||||
[SerializeField] private float BaseSpeed; // Базовая скорость
|
||||
[SerializeField] private float SprintSpeedMultiplier; // Множитель для бега
|
||||
[SerializeField] private float HandSpeedThreshold; // Порог скорости рук для бега
|
||||
private float CurrentSpeed; // Текущая скорость
|
||||
[SerializeField] private float HandSpeed;
|
||||
|
||||
// Stamina (выносливость)
|
||||
[SerializeField] private float MaxStamina; // Максимальная выносливость
|
||||
[SerializeField] private float Stamina; // Текущая выносливость
|
||||
[SerializeField] private float StaminaDrainRate; // Скорость расхода выносливости (единиц/сек)
|
||||
[SerializeField] private float StaminaRecoveryRate; // Скорость восстановления (единиц/сек)
|
||||
[SerializeField] private float LowStaminaMultiplier; // Снижение скорости при низкой выносливости
|
||||
[SerializeField] private float StaminaRecoveryDelay; // Задержка перед восстановлением после израсходования
|
||||
|
||||
[SerializeField] private bool IsRecovering = false; // Флаг для ожидания восстановления
|
||||
[SerializeField] private float RecoveryTimer; // Таймер восстановления
|
||||
[SerializeField] private bool IsPreRecovery = false;
|
||||
|
||||
void Start()
|
||||
{
|
||||
BaseSpeed = _MoveProvider.moveSpeed;
|
||||
PlayerPositionPreviousFrame = transform.position; // Set current positions
|
||||
PositionPreviousFrameLeftHand = LeftHand.transform.position; // Set previous positions
|
||||
PositionPreviousFrameRightHand = RightHand.transform.position;
|
||||
CurrentSpeed = BaseSpeed; // Initialize to base speed
|
||||
|
||||
Stamina = MaxStamina; // Инициализация выносливости
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// Get positions of hands
|
||||
PositionCurrentFrameLeftHand = LeftHand.transform.position;
|
||||
PositionCurrentFrameRightHand = RightHand.transform.position;
|
||||
|
||||
// Position of player
|
||||
PlayerPositionCurrentFrame = transform.position;
|
||||
|
||||
// Get distance the hands and player has moved from last frame
|
||||
var playerDistanceMoved = Vector3.Distance(PlayerPositionCurrentFrame, PlayerPositionPreviousFrame);
|
||||
var leftHandDistanceMoved = Vector3.Distance(PositionPreviousFrameLeftHand, PositionCurrentFrameLeftHand);
|
||||
var rightHandDistanceMoved = Vector3.Distance(PositionPreviousFrameRightHand, PositionCurrentFrameRightHand);
|
||||
|
||||
// Aggregate to get hand speed
|
||||
HandSpeed = ((leftHandDistanceMoved - playerDistanceMoved) + (rightHandDistanceMoved - playerDistanceMoved));
|
||||
|
||||
if (IsRecovering)
|
||||
{
|
||||
RecoveryTimer += Time.deltaTime;
|
||||
if (RecoveryTimer >= StaminaRecoveryDelay)
|
||||
{
|
||||
IsRecovering = false;
|
||||
RecoveryTimer = 0;
|
||||
}
|
||||
if (HandSpeed > HandSpeedThreshold)
|
||||
{
|
||||
CurrentSpeed = BaseSpeed; // Замедляем, если стамина истощена
|
||||
RecoveryTimer = 0;
|
||||
}
|
||||
}
|
||||
if (!IsRecovering)
|
||||
{
|
||||
Stamina += StaminaRecoveryRate * Time.deltaTime; // Восстанавливаем стамину
|
||||
Stamina = Mathf.Clamp(Stamina, 0, MaxStamina);
|
||||
|
||||
if (IsPreRecovery)
|
||||
{
|
||||
if (Stamina >= 0.5*MaxStamina)
|
||||
{
|
||||
IsPreRecovery = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (HandSpeed > HandSpeedThreshold)
|
||||
{
|
||||
Stamina -= StaminaDrainRate * Time.deltaTime; // Уменьшаем стамину
|
||||
Stamina = Mathf.Clamp(Stamina, 0, MaxStamina);
|
||||
if (!IsPreRecovery)
|
||||
{
|
||||
CurrentSpeed = BaseSpeed * SprintSpeedMultiplier; // Замедляем, если стамина истощена
|
||||
}
|
||||
else if (IsPreRecovery)
|
||||
{
|
||||
CurrentSpeed = BaseSpeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentSpeed = BaseSpeed;
|
||||
}
|
||||
}
|
||||
if (Stamina <= 0)
|
||||
{
|
||||
IsRecovering = true;
|
||||
IsPreRecovery = true;
|
||||
}
|
||||
_MoveProvider.moveSpeed = CurrentSpeed;
|
||||
|
||||
// Set previous position of hands for next frame
|
||||
PositionPreviousFrameLeftHand = PositionCurrentFrameLeftHand;
|
||||
PositionPreviousFrameRightHand = PositionCurrentFrameRightHand;
|
||||
// Set player position previous frame
|
||||
PlayerPositionPreviousFrame = PlayerPositionCurrentFrame;
|
||||
}
|
||||
}
|
11
Assets/Crossy Road VR/SwingingArmMotionScript.cs.meta
Normal file
11
Assets/Crossy Road VR/SwingingArmMotionScript.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2d54964b90d6903429f3430ea2ab1f61
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user