- Home /
Including camera angle into .Move direction
Hello! I am trying to code a dodge ability that will also factor in the y-axis (up). The expected function would be the player is moved a certain distance, if the player is looking up and standing still, they would dodge upward. Currently, this only affects the X/Z axis.
Additionally, is there a way to slow the movement by some controllable number?
private void OnDodge()
{
if (dodegTimer == 1.5f && allowDodge)
{
Vector3 inputDirectionForDodge = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized;
Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized;
_targetRotation = Mathf.Atan2(inputDirection.x, inputDirection.z) * Mathf.Rad2Deg + _mainCamera.transform.eulerAngles.y;
Vector3 targetDirection = Quaternion.Euler(0.0f, _targetRotation, 0.0f) * Vector3.forward;
_controller.Move(targetDirection.normalized * (dodgePower * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime);
//Debug.Log("This is a successful dodge run");
dodgeActive = true;
}
}
I've tried switching some of the code to reference the target rotation instead of input, but still the results are the same.
Could use some help.
Bumping this question, hoping for some help.
Your answer
Follow this Question
Related Questions
Having problem with Vector3.distance 1 Answer
Make Gameobject Stand On Surface Facing Certain Direction 0 Answers
direct a raycast from point a to point b 2 Answers
Get forward direction of face hitted by Raycast. 1 Answer
How to get object to face direction it's flying rather than looking at the target 2 Answers