- Home /
Jump working in editor runtime but not working in WebGL build
Hello, I wrote a simple script only for first-person-view character to jump. It works pretty well in editor runtime but not in standalone pc build or WebGL build. The code was first in the movement controller script where it had faced similar problem; I took out and tried several things that did not really work. Would you mind sharing any possible methods I should go and check? FYI, I left .isGrounded for the game purpose.
[SerializeField] private float jumpSpeed = 7.0f;
private Rigidbody rb;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
float _yMovement = Input.GetAxis("Jump");
//Apply jump
if (Input.GetAxis("Jump") != 0 || Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.V) || Input.GetKey("space"))
{
rb.AddForce(new Vector3(0, _yMovement * jumpSpeed, 0), ForceMode.Impulse);
}
}
Answer by HellsHand · May 03, 2021 at 08:36 PM
I'm not certain why this wouldn't work in a Build, unless you are hitting v
(see 2
), but some suggestions, .
float _yMovement = Input.GetAxis("Jump");
this returns between -1 and 1 so the most you get from your jumpSpeed is 0-7._yMovement
= 0 if you hitv
as it's not a default axis, you can however add it to the Inputs as a secondary positive input under project settings.GetAxis()
is a constant input likeGetKey()
it triggers for the entire time you are holding it down, so if you hold it down it will add force every frame.
Is it just not doing anything or something you don't want it to do?
Hi HellsHand, thanks for the suggestions. The reason that I have put 4 similar Get things for the Input was to test if there is something wrong with the keys in build. I added "v" as the secondary positive input and it worked well along with the rest (GetAxis, GetKeyDown, GetKey) in the editor. I already tried multiplying Time.deltatime in Vector3 just in case there are discrepancies in fps between editor and build; I couldn't jump still. I was wondering if there is something to do with Gravity, Dead, or Sensitivity in the input settings and adjusted them from 1000 to 30 for Gravity and Sensitivity while maintaining Dead at -0.0001; nothing worked. Or should I not pursue Addforce and try another option?
Can you get it to jump at all? If not have you tried going to extremes, Gravity = 0.0001, mass = 0.00001, jumpSpeed = 200, things like that.