Question by
akesolveigsir · Feb 05, 2019 at 05:46 PM ·
2d2d game2d-platformer2d-physics2d platformer
Problem with my dash ability,
Hello I recently got my dash to work but then i had trouble with the players jumps. It barely jumps and is glitching so hard. OBS my jumps were really good before i made the dash!!! Here's my jump code and dash code.
bool isJumping;
public float jumpForce;
void FixedUpdate() {
if (Input.GetKey(KeyCode.W) == true && !isJumping)
{
isJumping = true;
myRigidbody.AddForce(new Vector2(myRigidbody.velocity.x, jumpForce));
}
}
void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.CompareTag("Ground"))
{
isJumping = false;
myRigidbody.velocity = Vector2.zero;
}
}
Here's my dash code:
public float dashSpeed;
private float dashTime;
public float startDashTime;
void Start()
{
dashTime = startDashTime;
}
void FixedUpdate() {
if (dashTime <= 0)
{
dashTime = startDashTime;
myRigidbody.velocity = Vector3.zero;
}
else
{
dashTime -= Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space) == true && Input.GetKeyDown(KeyCode.D) == false && !facingRight)
{
myRigidbody.velocity = Vector3.left * dashSpeed;
}
else if (Input.GetKeyDown(KeyCode.Space) == true && Input.GetKeyDown(KeyCode.A) == false && facingRight)
{
myRigidbody.velocity = Vector3.right * dashSpeed;
}
}
},
Comment
Best Answer
Answer by xxmariofer · Feb 05, 2019 at 08:14 PM
hello, first dont catch the inputs in the fixedupdate or it wont catch all the inputs. second i think your issue is setting the rigidbody velocity, rather than adding a force like yoou did in the jump, setting the velocity will remove all the velocitys (like the jump) and set just the velocity on the dash.
but your jumps are not working never or just when you are dashing?
They work when i didnt have the dash code in