Forum Replies Created

Viewing 4 replies - 31 through 34 (of 34 total)

1 2 3
john P
Up
0
Down
::

That Great.. Thanks for help..

David N
Up
0
Down
::

Well the thing is CharacterController doesn’t have a velocity like the Rigidbody.

If you want to apply a certain movement over a range of time you need to iterate each frame and apply according resulting movement.

Currently your Move is only called exactly once – either with the entire forces – jumps – or with the velocity (after applying Time.deltaTime) but only for a single frame -> barely moves at all.

 

[SerializeField] float slideForce = 3f;

[SerializeField] float wallJumpHeight = 3f;
[SerializeField] float wallJumpRange = 3f;
[SerializeField] float wallJumpGravity = 9.8f;
[SerializeField] float jumpDuration = 2f;

bool doWallJump = false;

private void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.normal.y < 0.3f)
{
Debug.DrawRay(hit.point, hit.normal, Color.red, 1.25f);

if ((Keyboard.current.spaceKey.isPressed || (Gamepad.current != null && Gamepad.current.buttonSouth.isPressed)))
{
var horizontalMovement = hit.normal;
Debug.DrawRay(hit.point, hit.normal, Color.yellow, 1.25f);
_controller.enabled = true;

doWallJump = true;

float verticalVelocity = Mathf.Sqrt(wallJumpHeight * wallJumpRange * wallJumpGravity);

if(currentJumpRoutine!= null) StopCoroutine(currentJumpRoutine);
currentJumpRoutine = StartCoroutine(ApplyJumpOverTime(horizontalMovement, verticalVelocity, jumpDuration));
}
}
}

private IEnuermator ApplyJumpOverTime(Vector3 horizontalMovement, float verticalVelocity, float jumpDuration)
{
for(var timePassed = 0f; timePassed < jumpDuration; timePassed += Time.deltaTime)
{
_controller.Move((horizontalMovement.normalized + new Vector3(0.0f, verticalVelocity, 0.0f)) * Time.deltaTime);
yield return null;
}

currentJumpRoutine = null;
}

 

usually you would have all user input in a single script and locally store an overall applied movement vector where you than apply the user input and gravity etc to. Then in Update (-> every frame) you apply that movement to the CharacterController.Move

Faisal Khan
Up
0
Down
::

You should read these 2 articles. I thinks that will helpful for you

 

5 Ways Make Money as a 3D Artist in 2023

Your Path to Success in 3D Animation Careers

Muntaha Haider
Up
0
Down
::

Did you get Job of 3d animation services ?

Viewing 4 replies - 31 through 34 (of 34 total)

1 2 3
New to Communities?

New to Communities?

Ask a Question