#2D top down dash problem

1 messages · Page 1 of 1 (latest)

warped geode
#

I am trying to add dash to my game, but after finishing a tutorial these errors show au and I dont know what the mean. I will be very happy If someone could help me

ebon zodiac
#

[]cb

steep elmBOT
#

Use codeblocks to send code in a message!

To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.

For example:
```cs
Console.WriteLine("Hello World");
```

Produces:

Console.WriteLine("Hello World");

To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.

warped geode
#
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
   public float moveSpeed;
   float speedX, speedY;
   Rigidbody2D rb;
   public Animator animator;
   Vector2 movement;
   [Header("Dash Settings")]
   [SerializeField] float dashSpeed = 10f;
   [SerializeField] float dashDuration = 1f;
   [SerializeField] float dashCooldown = 1f;
   bool isDashing;
   bool canDash = true;
   void Start()
   {

    rb = GetComponent<Rigidbody2D>();
    canDash = true;
   }


}

   void Update()
   {
     if (isDashing)
     {
         return;
     }
     speedX = Input.GetAxisRaw("Horizontal") * moveSpeed;
     speedY = Input.GetAxisRaw("Vertical") * moveSpeed;
     rb.velocity = new Vector2(speedX, speedY);


     animator.SetFloat("Horizontal", movement.x);
     animator.SetFloat("Vertical", movement.y);
     animator.SetFloat("Speed", movement.sqrMagnitude);

     if(Input.GetKeyDown(KeyCode.Space) && canDash)
     {
         StartCorutine(Dash());
     }
   }

    
   

   public IE Dash()
   {
       canDash = false;
       isDashing = true;
       rb.velocity = new Vector2(speedX * dashSpeed, speedY * dashSpeed);
       yield return new WaitforSeconds (dashDuration);
       isDashing = false;
       
       yield return new WaitforSeconds(dashCooldown);
       canDash = true;
   }
}
#

@ebon zodiac

sturdy blade
#

I see that you've added an extra "}" before void update method.

#

And not sure if IE would work, i dont know if it does work like that though. Try using "IEnumerator" instead of IE.

#

Let me know if it works.

#

@warped geode

warped geode
#

@sturdy blade

#

Unfortunetly doesnt work 😦

sturdy blade
#

Coroutine spelling error.

warped geode
#

oh

#

thx

#

but the other errors are still there

#

I am sorry

#

I am very noob at programming

#

@sturdy blade

sturdy blade
#

using System.Collections;

#

Me too..

warped geode
sturdy blade
warped geode
#

i have this

#

sorry

sturdy blade
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
float speedX, speedY;
Rigidbody2D rb;
public Animator animator;
Vector2 movement;
[Header("Dash Settings")]
[SerializeField] float dashSpeed = 10f;
[SerializeField] float dashDuration = 1f;
[SerializeField] float dashCooldown = 1f;
bool isDashing;
bool canDash = true;
void Start()
{

rb = GetComponent<Rigidbody2D>();
canDash = true;

}

void Update()
{
if (isDashing)
{
return;
}
speedX = Input.GetAxisRaw("Horizontal") * moveSpeed;
speedY = Input.GetAxisRaw("Vertical") * moveSpeed;
rb.velocity = new Vector2(speedX, speedY);

 animator.SetFloat("Horizontal", movement.x);
 animator.SetFloat("Vertical", movement.y);
 animator.SetFloat("Speed", movement.sqrMagnitude);

 if(Input.GetKeyDown(KeyCode.Space) && canDash)
 {
     StartCoroutine(Dash());
 }

}

public IEnumerator Dash()
{
canDash = false;
isDashing = true;
rb.velocity = new Vector2(speedX * dashSpeed, speedY * dashSpeed);
yield return new WaitforSeconds (dashDuration);
isDashing = false;

   yield return new WaitforSeconds(dashCooldown);
   canDash = true;

}
}

warped geode
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
   public float moveSpeed;
   float speedX, speedY;
   Rigidbody2D rb;
   public Animator animator;
   Vector2 movement;
   [Header("Dash Settings")]
   [SerializeField] float dashSpeed = 10f;
   [SerializeField] float dashDuration = 1f;
   [SerializeField] float dashCooldown = 1f;
   bool isDashing;
   bool canDash = true;
   void Start()
   {

    rb = GetComponent<Rigidbody2D>();
    canDash = true;
   }




   void Update()
   {
     if (isDashing)
     {
         return;
     }
     speedX = Input.GetAxisRaw("Horizontal") * moveSpeed;
     speedY = Input.GetAxisRaw("Vertical") * moveSpeed;
     rb.velocity = new Vector2(speedX, speedY);


     animator.SetFloat("Horizontal", movement.x);
     animator.SetFloat("Vertical", movement.y);
     animator.SetFloat("Speed", movement.sqrMagnitude);

     if(Input.GetKeyDown(KeyCode.Space) && canDash)
     {
         StartCoroutine(Dash());
     }
   }

    
   

   public IEnumerator Dash()
   {
       canDash = false;
       isDashing = true;
       rb.velocity = new Vector2(speedX * dashSpeed, speedY * dashSpeed);
       yield return new WaitforSeconds (dashDuration);
       isDashing = false;
       
       yield return new WaitforSeconds(dashCooldown);
       canDash = true;
   }
}
sturdy blade
#

Remove "cs".

warped geode
#

cs is to copy script for this discord server

sturdy blade
#

Oh, my bad. Whats the final error?

warped geode
sturdy blade
#

Oh I'm so silly. It should be WaitForSceconds and not WaitforSeconds.

#

A capital F.

warped geode
#

i

#

OMG

#

sorry

sturdy blade
#

It should solve the issues

#

Happens with best of us. Make sure to use intellisense..

#

Makes the job easier.

sturdy blade
#

It helps correct and complete the code. Google it. How to enable intellisense for unity in visual studio.

warped geode
#

😔

sturdy blade
#

Bruh! Still written wrong spelling. Copy and paste this WaitForSeconds()

warped geode
#

I had that

#

its still wrong

#

o

#

ok

#

F not f

#

ok

sturdy blade
#

Yes!

warped geode
#

YEY

#

thx

#

so much

#

its working

#

thx a lot

#

!!!

sturdy blade
#

Glad i colud help, Now quit visual studio and enable intellisense and reload the script.

#

Most of the issues will be solved

warped geode
#

ok

#

thx a lot

#

hope youre having a fantastic day

sturdy blade
sturdy blade
warped geode
#

but when i press play

#

the screen goes black

sturdy blade
#

It should work.. try reloading. Works on most browsers.

warped geode
#

OMG

#

this game is great

#

I sucl

#

suck*

#

died like 10 times

#

but it reminds me of my childchood

#

hope you win

sturdy blade
#

Hehe thanks for wishes.. i enjoyed making it. Glad you liked it.

#

Keep coding! 🙂