I have a dashing mechanic in my game. I was using Transform, but since transform doesn't account for physics I was going through walls on occasion. I'm trying to use addforce, but it doesn't have the quick burst of speed effect as previously.
how can I use addforce to make the dash seem more like a dash?
I think my dash's cooldown is messed up too, allowing the player to spam the button, instead of using it once, then having to wait. If someone could check that out it would help me alot too.
if(Input.GetKey(KeyCode.LeftShift) && canIDash == true){
if(direction == true)
{
dashTimer += Time.deltaTime*3;
rigidbody.AddForce(Vector3.right*50);
}
if (direction == false)
{
dashTimer += Time.deltaTime*3;
rigidbody.AddForce(Vector3.left*50);
}
}
if(dashTimer > .5f)
{
canIDash = false;
dashCooldown = true;
}
if(dashTimer < .5f && dashCooldown == false)
{
canIDash = true;
}
if(dashTimer <= 0)
{
dashCooldown = false;
}
}
EDIT:
____________________________________________________________________________
This is what the script currently looks like, it still doesn't work perfect. If anyone can help it would be awesome.
public class DashAbility : MonoBehaviour {
public float dashCooldown;
public bool canIDash = true;
public Vector2 savedVelocity;
void Update ()
{
if(dashCooldown > 0)
{
canIDash = false;
dashCooldown -= Time.deltaTime;
//if I put saved velocity here, it will continue to move at savedVelocity until dashCooldown = 0? so it can't go here? right?
}
if(dashCooldown <= 0)
{
canIDash = true;
//if I put savedVelocity here it doesn't return to savedVelocity until dashCooldown <=0 so... it doesn't go here either right...?
}
if(Input.GetKeyDown(KeyCode.LeftShift) && canIDash == true)
{
//saves velocity prior to dashing
savedVelocity = rigidbody.velocity;
//this part is the actual dash itself
rigidbody.velocity = new Vector2(rigidbody.velocity.x*3f, rigidbody.velocity.y);
//sets up a cooldown so you have to wait to dash again
dashCooldown = 2;
}
}
↧