C
C#2mo ago
eduardoA

Does not dash

Hello I have a player script, and I am trying to make a dash ability, but when I press the button nothing happens. I put a debug to see if it printed something and it did, but it doesn't accelerate my player or o anything, I also set variables in the inspector
// Update is called once per frame
void Update() {

Vector2 currentVelocity = PlayerRB.velocity;

isOnGround = Physics2D.OverlapCircle(groundPoint.position,
.2f, whatIsGround);

if (Input.GetButtonDown("Fire2")) {

dashCunter = dashTime;

}

if (dashCunter > 0) {

dashCunter -= Time.deltaTime;

PlayerRB.velocity = new Vector2(dashSpeed * transform.localScale.x, PlayerRB.velocity.y);

}
else {
currentVelocity.x = Input.GetAxisRaw(HORIZONTAL) * moveSpeed;

if (currentVelocity.x < 0) {

transform.localScale = new Vector3(-1f, 1f, 1f);
}
else if (currentVelocity.x > 0) {

transform.localScale = Vector3.one;
}
}
if (Input.GetButtonDown(JUMP) && (isOnGround || canDoubleJump)) {

if (isOnGround) {
canDoubleJump = true;
}
else {
canDoubleJump = false;

animator.SetTrigger("DoubleJump");
}
currentVelocity.y = jumpForce;
}

if (Input.GetButtonDown(FIRE)) {

Instantiate(shotToFire, shotPoint.position,
shotPoint.rotation).setBulletDir(new Vector2(transform.localScale.x, 0));

animator.SetTrigger("ShoFire");
}

PlayerRB.velocity = currentVelocity;

animator.SetBool("IsOnGrund", isOnGround);
animator.SetFloat("Spped", Mathf.Abs(PlayerRB.velocity.x));
}
}
// Update is called once per frame
void Update() {

Vector2 currentVelocity = PlayerRB.velocity;

isOnGround = Physics2D.OverlapCircle(groundPoint.position,
.2f, whatIsGround);

if (Input.GetButtonDown("Fire2")) {

dashCunter = dashTime;

}

if (dashCunter > 0) {

dashCunter -= Time.deltaTime;

PlayerRB.velocity = new Vector2(dashSpeed * transform.localScale.x, PlayerRB.velocity.y);

}
else {
currentVelocity.x = Input.GetAxisRaw(HORIZONTAL) * moveSpeed;

if (currentVelocity.x < 0) {

transform.localScale = new Vector3(-1f, 1f, 1f);
}
else if (currentVelocity.x > 0) {

transform.localScale = Vector3.one;
}
}
if (Input.GetButtonDown(JUMP) && (isOnGround || canDoubleJump)) {

if (isOnGround) {
canDoubleJump = true;
}
else {
canDoubleJump = false;

animator.SetTrigger("DoubleJump");
}
currentVelocity.y = jumpForce;
}

if (Input.GetButtonDown(FIRE)) {

Instantiate(shotToFire, shotPoint.position,
shotPoint.rotation).setBulletDir(new Vector2(transform.localScale.x, 0));

animator.SetTrigger("ShoFire");
}

PlayerRB.velocity = currentVelocity;

animator.SetBool("IsOnGrund", isOnGround);
animator.SetFloat("Spped", Mathf.Abs(PlayerRB.velocity.x));
}
}
I am using unity 2022.3.20f1 Windows 11 Visual Studio 2022 Laptop specs Amd ryzen 9 5800hx 64Gb ram 1tb nvidia rtx 3070
No description
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server