Search Unity

Need help making a dash

Discussion in '2D' started by xXjojo440Xx, Oct 21, 2019.

  1. xXjojo440Xx

    xXjojo440Xx

    Joined:
    Oct 1, 2019
    Posts:
    13
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public float moveSpeed;
    public float dashRange;
    public Rigidbody2D rb;
    public Camera cam;
    Vector2 movement;
    Vector2 mousePos;

    void Update()
    {

    movement.x = Input.GetAxisRaw("Horizontal");
    movement.y = Input.GetAxisRaw("Vertical");

    mousePos = cam.ScreenToWorldPoint(Input.mousePosition);

    if (Input.GetKeyDown(KeyCode.Space))
    {

    }
    }


    void FixedUpdate()
    {
    rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);

    Vector2 lookDir = mousePos - rb.position;
    float angle = Mathf.Atan2(lookDir.y, lookDir.x) * Mathf.Rad2Deg - 90f;
    rb.rotation = angle;
    }

    this is my current player movement still learning alot but its a simple 2d triangle sprite that i can move around while it points at the mouse and i can shoot projectiles, trying to make a dash when pressing space, either towards the mouse position or even in the last move direction, but having a hard time figuring it out any help would be greatly appreciated
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    Please use code tags.

     
    DWriedt likes this.
  3. xXjojo440Xx

    xXjojo440Xx

    Joined:
    Oct 1, 2019
    Posts:
    13
    sorry not sure what you mean by use code tags.. im new to coding and forums in general xD thank you for the response though ill try to get it working using the video
     
  4. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    1,465
    No problem. Check out the image for the code tags button on the text ribbon:

    upload_2019-10-22_8-32-17.png
     
    xXjojo440Xx likes this.