#show my how the jump script works
1 messages · Page 1 of 1 (latest)
..
I cant seem to send the code
private void JumpAndGravity()
{
if (Grounded)
{
// reset the fall timeout timer
_fallTimeoutDelta = FallTimeout;
// update animator if using character
if (_hasAnimator)
{
_animator.SetBool(_animIDJump, false);
_animator.SetBool(_animIDFreeFall, false);
}
// stop our velocity dropping infinitely when grounded
if (_verticalVelocity < 0.0f)
{
_verticalVelocity = -2f;
}
// Jump
if (_input.jump && _jumpTimeoutDelta <= 0.0f)
{
Debug.Log("JUMPED");
// the square root of H * -2 * G = how much velocity needed to reach desired height
_verticalVelocity = Mathf.Sqrt(JumpHeight * -2f * Gravity);
// update animator if using character
if (_hasAnimator)
{
_animator.SetBool(_animIDJump, true);
}
}
// jump timeout
if (_jumpTimeoutDelta >= 0.0f)
{
_jumpTimeoutDelta -= Time.deltaTime;
}
}
else
{
// reset the jump timeout timer
_jumpTimeoutDelta = JumpTimeout;
// fall timeout
if (_fallTimeoutDelta >= 0.0f)
{
_fallTimeoutDelta -= Time.deltaTime;
}
else
{
// update animator if using character
if (_hasAnimator)
{
_animator.SetBool(_animIDFreeFall, true);
}
}
// if we are not grounded, do not jump
_input.jump = false;
}
// apply gravity over time if under terminal (multiply by delta time twice to linearly speed up over time)
if (_verticalVelocity < _terminalVelocity)
{
_verticalVelocity += Gravity * Time.deltaTime;
}
}
ok yeah here you go
its the unity's starter asset if you want to check it out for yourself but here is the code
unity starter is an example of how unity works, it has a lot of flaws
basically the thing happening here is your character keep jumping because it's never in airborn
well thats disappointing
you have to fix that yourself by changing the hitbox of the character
what do you recommend?
changing the entire character controller or should I try to fix that?
what i did is remake all the jump and landing scripts
and also adjust the landing hitbox to make it never larger than the player hitbox
One easy solution to fix it : put a timer between each jumps
variables
[SerializeField] private float TimeInAir = 0f;
[SerializeField] private float TimeToJump = 0.5f;
there is already a time to jump I think
its set to like .5
yeah its called jumptimout
public float JumpTimeout = 0.50f;```
alright so
you jump only once and then it keeps jumping again even if you don't press jump ?
yeah I just need to press W pressing any other key will stop the auto jump
its linked to the StartAssetsInputs
_input = GetComponent<StarterAssetsInputs>();```
this only happens if you jump while being stuck on a wall ?
so basically I go to the slightly slanted wall, I just once and press W, after that the character will keep jumping
if the wall is not perfectly 90 degrees I am able to climb it
but what if you jump anywhere else, in the middle of the road for example
alright
the thing i did is use the tags
yeah no it only happens when jumping on a slanted wall
i put "walkable" as a tag for all my roads, but never on buildings or on places i don't want the character to go
is it the same if I use layers?
and in the jumping / running / walking script, in code i used "OnTriggerStay"
i prefer tags
but layers can work, never tryed
if the character OnTriggerStay Collider.tag or Collider.name == "Walkable" then he can walk/run/jump
private void OnTriggerStay(Collider m_otherCollider)
{
if (m_otherCollider.name == "Walkable")
{
CharacterGroundedInformations.M_IsGrounded = true;
my_character_first_jump.M_OtherJump = 1;
IsAirborn = false;
}
}
I tried layers and basically the character gets stuck on the wall, doesnt auto jump anymore but stays there stuck in "falling" animation
ill try that
i used my own variables in there, you have to use yours
yes you have to make sure the player will slide out of it
or else you can use the raycast
I dont have an idea on how I can do that would you mind elaborating?
basically you make your character throw multiple raycasts around him, and if it a wall too close, then it cannot got toward it anymore
you can use materials and gravity
alright thanks ill try that