- Home /
Question by
watercat · Dec 31, 2017 at 01:55 PM ·
jump2d-gameplayproblema
Unity 2D jump problem
(basic Unity 2d controller code)when a player uses both jump buttons at the same time the value of height doubles.how can i fix it?
Comment
C code
using System;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
namespace UnityStandardAssets._2D
{
[RequireComponent(typeof (PlatformerCharacter2D))]
public class Platformer2DUserControl : $$anonymous$$onoBehaviour
{
private PlatformerCharacter2D m_Character;
private bool m_Jump;
private void Awake()
{
m_Character = GetComponent<PlatformerCharacter2D>();
}
private void Update()
{
if (!m_Jump)
{
// Read the jump input in Update so button presses aren't missed.
m_Jump = CrossPlatformInput$$anonymous$$anager.GetButtonDown("p1 Jump");
}
}
private void FixedUpdate()
{
// Read the inputs.
bool crouch = Input.GetButton("p1 Duck");
float h = CrossPlatformInput$$anonymous$$anager.GetAxis("p1 Walk");
// Pass all parameters to the character control script.
m_Character.$$anonymous$$ove(h, crouch, m_Jump);
m_Jump = false;
}
}
}
Best Answer
Answer by JuanMendez88 · Feb 06, 2018 at 10:22 PM
How are you reading the input? If you're reading the input in a key by key basis you can use an "or". if you're using GetAxis the value should be normalized regardless of whether you're pressing one or more keys with the same axis value.
private void Update()
{
//registering keys
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.A))
{
//jump
}
//using axis
float jumpForce = Input.GetAxis("Jump");
//do something with the axis value, which is normalized
}
Your answer
Follow this Question
Related Questions
I Can't Jump, And If I Remove if(isGrounded) I Can Do More Then 10 Jumps IN The Air 1 Answer
Help with player script. 1 Answer
I need help with animations. 0 Answers
Strange Jumping Error? 1 Answer
I need character only jump 1 Answer