dashing in unity 2d top down questions?
Hello, I have created a pretty janky 2d dash script, that works but the character tends to overshoot the mouse point so I divided the mouse's position by 2 which makes it now very slow. I think this gem of a game that was an entry into Ludum dare 33 https://overboy.itch.io/mobs-inc has a dash mechanic which I think's really reflects what I'm trying to create, something that has a maximum dash distance but no minimum. Does anyone have some edits/suggestions to create something more smooth? Here is my script without animations implemented:
public class test : MonoBehaviour { public float speed = 10f; public Rigidbody2D rigidbody; public float dashSpeed=10f; void Start() { } void Update() { Vector2 direction = Camera.main.ScreenToWorldPoint(Input.mousePosition)-transform.position; float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg; Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward); transform.rotation = Quaternion.Slerp(transform.rotation, rotation, speed * Time.deltaTime); rigidbody.velocity = Vector2.zero; Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); mousePosition.x = mousePosition.x/2; mousePosition.y = mousePosition.y/2; if(Input.GetButtonDown("Fire1")) { rigidbody.AddForce(mousePosition*dashSpeed); } } }
Your answer
![](https://koobas.hobune.stream/wayback/20220613051752im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Homing attack suggestion 0 Answers
How to do dodge Unity2D like Crossing Souls or Hyper Light Drifter. 0 Answers
dash till puff game 0 Answers
Doodle Jump Game Platform Spawn Issue Unity2D 0 Answers
Having a non teleport dash 2 Answers