dash in movement dir

This commit is contained in:
Xaver Drabik 2024-12-18 15:19:25 +01:00
parent fadd6fe57a
commit e6892214ea
9 changed files with 6 additions and 124 deletions

View File

@ -45,8 +45,7 @@ void Start()
_camera = _cameraGameObject.GetComponent<Camera>();
_controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
Vector3 input = new Vector3(_inputManager.moveInput.x, 0f , _inputManager.moveInput.y);
@ -71,6 +70,7 @@ void ApplyMovement(Vector3 moveDir, Vector3 lookTarget)
}
}
Vector3 _lastMoveDir = Vector3.zero;
Vector3 MoveDir(Vector3 input)
{
if (_dashing)
@ -80,7 +80,8 @@ Vector3 MoveDir(Vector3 input)
Quaternion camRotation = Quaternion.Euler(0f, _cameraGameObject.transform.rotation.eulerAngles.y, 0f);
input = camRotation * input;
_lastMoveDir = input;
return input;
}
@ -114,9 +115,7 @@ Vector3 LookTarget()
Vector3 aimTargetPosition = hit.collider.transform.position;
float distanceToTarget = Vector3.Distance(transform.position, aimTargetPosition);
float assistStrength = distanceToTarget <= minAimDistance
? 1f // Full strength if within minAimDistance
: Mathf.Clamp01(1 - (distanceToTarget - minAimDistance) / (maxAimDistance - minAimDistance));
float assistStrength = Mathf.Clamp(1-(distanceToTarget - minAimDistance) / (maxAimDistance - minAimDistance), 0f, .6f);
targetPoint = Vector3.Lerp(targetPoint, aimTargetPosition, assistStrength);
@ -148,7 +147,7 @@ private IEnumerator DashCoroutine()
float startTime = Time.time;
while(Time.time < startTime + dashTime)
{
_controller.Move(transform.forward * dashSpeed * Time.deltaTime);
_controller.Move(_lastMoveDir * dashSpeed * Time.deltaTime);
yield return null;
}
_dashing = false;

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 2c1b0f7967bd84431ba19240b39e2f1b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,22 +0,0 @@
using UnityEngine;
using UnityEngine.AI;
public class EnemyMove : MonoBehaviour
{
public GameObject player;
private NavMeshAgent _meshAgent;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_meshAgent = GetComponent<NavMeshAgent>();
}
// Update is called once per frame
void Update()
{
Vector3 playerPos = player.transform.position;
_meshAgent.SetDestination(playerPos);
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: f4f29a7caf57449789b9106e40d9bb19

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f06a034470c5546838be0794f5bb513a
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,27 +0,0 @@
using UnityEngine;
public class CameraMove : MonoBehaviour
{
public Vector3 camOffset;
[SerializeField] private GameObject player;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void LateUpdate()
{
camOffset.z = camOffset.x;
Vector3 desiredCamPos = player.transform.position;
desiredCamPos.x += camOffset.x;
desiredCamPos.y += camOffset.y;
desiredCamPos.z += camOffset.z;
transform.position = desiredCamPos;
transform.LookAt(player.transform);
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 05236f4b383a944c19e8c2cdfb026e66

View File

@ -1,46 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMove : MonoBehaviour
{
[Range(0f, 10f)]
public float moveSpeed = 5f;
[SerializeField]
private InputManager _inputManager;
[SerializeField]
private GameObject _camera;
private CharacterController _controller;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
_controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
Vector3 input = new Vector3(_inputManager.moveInput.x, 0f , _inputManager.moveInput.y);
Vector3 moveDir = Vector3.zero;
moveDir += MoveDir(input);
moveDir += Gravity();
_controller.Move(moveSpeed * moveDir * Time.deltaTime);
}
Vector3 MoveDir(Vector3 input)
{
Quaternion camRotation = Quaternion.Euler(0f, _camera.transform.rotation.eulerAngles.y, 0f);
input = camRotation * input;
return input;
}
Vector3 Gravity()
{
return Physics.gravity;
}
}

View File

@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 726bb6542b066483c9e1c5ab04620ffe