- Home /
Need Help Getting My Player To Jump.
I added Photon To My Game And Now My Player Wont Jump, Not Sure What Is Causing this issue. I had him jumping after but Something happened and I Had To Re import my player Model and start from scratch, I used all of the same code, and even attached a Rigidbody and Capsule collider to the player and I can not for the life of me figure out why when I hit space that the player won't jump. Maybe someone can steer me in the right direction. Here is all the code involved with making the player jump. I know it's something simple, Just can't figure it out. Dnt even kno if it's something to do with the code.
[Header("Jump Settings")]
public Vector3 jump;
public float jumpForce = 2.0f;
public float floorAngleThreshhold = 15.0f;
public bool IsGrounded = false;
Rigidbody RB;
private void Start()
{
_animator = GetComponent<Animator>();
RB = GetComponent<Rigidbody>();
jump = new Vector3(0.0f, 2.0f, 0.0f);
}
private void OnCollisionStay(Collision col)
{
foreach (ContactPoint hit in col)
{
if (Vector3.Angle(Vector3.up, hit.normal) <= floorAngleThreshhold)
{
IsGrounded = true;
return;
}
}
}
private void OnCollisionExit()
{
IsGrounded = false;
}
private void Jump()
{
if (IsGrounded)
{
if (Input.GetKeyDown(KeyCode.Space) && PlayerStat.StaminaBar.value > 0.3)
{
RB.AddForce(jump * jumpForce, ForceMode.Impulse);
_animator.SetTrigger("IsJumping");
}
else
{
_animator.SetBool("IsFalling", false);
_animator.SetBool("Landing", true);
}
}
else
{
_animator.SetBool("IsFalling", true);
}
}
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && PlayerStat.Sta$$anonymous$$aBar.value > 0.3)
Should be
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && PlayerStat.Sta$$anonymous$$aBar.value > 0.3f)<- missing "f"
but that isn't your issue. Also the redundant else seems pointless to me.
bool check=false;
private void Jump()
{
if (IsGrounded)
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Space) && PlayerStat.Sta$$anonymous$$aBar.value > 0.3)
{
RB.AddForce(jump * jumpForce, Force$$anonymous$$ode.Impulse);
_animator.SetTrigger("IsJumping");
_animator.SetBool("Jumping",true);
}
check=_animator.GetBool("Jumping");
while(check)
{
_animator.SetBool("Landing", true);
}
}
while(Equals(IsGrounded,false))
{
_animator.SetBool("Falling", true);
}else{
_animator.SetBool("Falling", false);
}
}
Its also possible that your transitions are not set correctly on your animator
Answer by Eno-Khaon · Feb 17, 2019 at 05:29 AM
I don't see the Jump() function being called from anywhere, so there's no clear time during which your character *should* jump.
To rectify that, you could use something as simple as:
void Update()
{
Jump();
}
If you continue to have any trouble after that, there are a few potential issues that could be looked into:
By using ForceMode.Impulse and not multiplying the force by the mass of the Rigidbody, the jump could wind up being weaker than expected if you ever decide to modify the Rigidbody's mass. By extension, it's not required either, but since you appear to be using a 3D Rigidbody, the jump force could alternatively be applied using ForceMode.VelocityChange to inherently ignore mass (not applicable for Rigidbody2D).
Also, you're applying something of an out-of-nowhere multiplication to the force of the jump in your Start() function when you set your "jump" variable.
jump = new Vector3(0.0f, 2.0f, 0.0f);
Since that effectively doubles the value of your "jumpForce" variable, it's really just a bit misleading. It would probably be more convenient for your own sake to set it to Vector3.up or, if you want to counter gravity more directly:
jump = -Physics.gravity.normalized; // default Vector3(0, 1, 0)
With that change made, you'd just need to increase the "jumpForce" value to get back to where it started.
made the changes you suggested and still can't jump. It's Weird. I fixed it earlier by just tagging my camera, $$anonymous$$ain camera. But after I re imported the character it stopped working. Everything else evolving the Rigidbody in my script works accept jumping, Could it b something to do with checking to see if the player is grounded not functioning properly?
Well, if it changed after re-importing, then is anything unusual with your "PlayerStat.Sta$$anonymous$$aBar.value" value? Unless there's something especially unusual regarding the environment (like, if the character were touching and leaving ground every frame), then the "isGrounded" check should be good enough.
Nope, Nothing unusual with the PlayerStat.Sta$$anonymous$$aBar.Value and the environment is not unusual either everything is the same way I had it. It's so weird. I just dnt understand it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612191839im_/https://answers.unity.com/themes/thub/images/avi.jpg)