Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by muhammadmohid · Aug 07, 2019 at 07:30 AM · rpgattacktop down shooterdash

How Do I Make A Dash&Attack Move For My Top-DownRPG 2D?

alt text I Made This RPG Kinda Game And Unfortunately I Can Make Any Attack Movement. I Want Kind Of Like A Dash Attack That Kills These Slimes. At the moment the slimes just reduce your health on collision and you die if it reaches zero. Also I Have A Crosshair That Is Restricted and cant go far from the player, and I want To Dash&Attack In The Direction Of My Crosshair. I Want To Be Able To Kill Them And Also Detect That I Have Killed The Specific Slime Because I Want The Slime As An Item In Future. Here Is My Movement Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
     public GameObject player;
     public Animator animator;
     public float movementSpeed;
     public float runSpeed;
     public int sprintDuration=150;
     int sprintRemaining=100;
     public GameObject footstepGrass;
     public GameObject footstepGrassSprint;
     public GameObject footstepPlanks;
     public GameObject footstepPlanksSprint;
     public GameObject footstepCave;
     public GameObject footstepCaveSprint;
     public GameObject caveParticles;
     public GameObject groundMaterial;
     public Rigidbody2D rb;
     Vector3 movement;
     Vector3 aim;
     bool isAiming;
     bool endofAiming;
     bool isSprinting;
     
     void Update() 
     {
         ProcessInputs();
         Animate();
         Move();
         Footsteps();
     }
     
     private void ProcessInputs()
     {
         movement = new Vector3(Input.GetAxis("MoveHorizontal"), Input.GetAxis("MoveVertical"), 0.0f);
 
         if(movement.magnitude > 1.0f)
         {
             movement.Normalize();
         }
        
     }
 
     private void Footsteps()
     {   
 
         if(Input.GetAxis("MoveHorizontal") != 0 && !isSprinting && groundMaterial.tag == "Grass")
         {
             footstepGrass.SetActive(true);
         }
         else if(Input.GetAxis("MoveVertical") != 0 && !isSprinting && groundMaterial.tag == "Grass")
         {
             footstepGrass.SetActive(true);
         }
         else if(Input.GetAxis("MoveHorizontal") != 0 && isSprinting && groundMaterial.tag == "Grass")
         {
             footstepGrassSprint.SetActive(true);
         }
          else if(Input.GetAxis("MoveVertical") != 0 && isSprinting && groundMaterial.tag == "Grass")
         {
             footstepGrassSprint.SetActive(true);
         }
         else
         {
             footstepGrass.SetActive(false);
             footstepGrassSprint.SetActive(false);
         }
 
         if(Input.GetAxis("MoveHorizontal") != 0 && !isSprinting && groundMaterial.tag == "Planks")
         {
             footstepPlanks.SetActive(true);
         }
         else if(Input.GetAxis("MoveVertical") != 0 && !isSprinting && groundMaterial.tag == "Planks")
         {
             footstepPlanks.SetActive(true);
         }
         else if(Input.GetAxis("MoveHorizontal") != 0 && isSprinting && groundMaterial.tag == "Planks")
         {
             footstepPlanksSprint.SetActive(true);
         }
          else if(Input.GetAxis("MoveVertical") != 0 && isSprinting && groundMaterial.tag == "Planks")
         {
             footstepPlanksSprint.SetActive(true);
         }
         else
         {
             footstepPlanksSprint.SetActive(false);
             footstepPlanks.SetActive(false);
         }
 
         if(Input.GetAxis("MoveHorizontal") != 0 && !isSprinting && groundMaterial.tag == "Cave")
         {
             footstepCave.SetActive(true);
         }
         else if(Input.GetAxis("MoveVertical") != 0 && !isSprinting && groundMaterial.tag == "Cave")
         {
             footstepCave.SetActive(true);
         }
         else if(Input.GetAxis("MoveHorizontal") != 0 && isSprinting && groundMaterial.tag == "Cave")
         {
             footstepCaveSprint.SetActive(true);
         }
          else if(Input.GetAxis("MoveVertical") != 0 && isSprinting && groundMaterial.tag == "Cave")
         {
             footstepCaveSprint.SetActive(true);
         }
         else
         {
             footstepCaveSprint.SetActive(false);
             footstepCave.SetActive(false);
         }
     }
     
     private void Move()
     {
         //transform.position = transform.position + movement * Time.deltaTime * movementSpeed;
         rb.velocity = new Vector2(movement.x, movement.y);
 
         if(Input.GetAxis("Sprint") != 0 && sprintRemaining > 0)
        {
            transform.position = transform.position + movement * Time.deltaTime * runSpeed;
            sprintRemaining -= 1;
            isSprinting = true;
        }
        else if(Input.GetAxis("Sprint") == 0 && sprintRemaining < sprintDuration)
        {
            sprintRemaining++;
        }
        else
        {
            isSprinting = false;
        }
     }
 
     private void Animate()
     {
             animator.SetFloat("Horizontal", movement.x);
             animator.SetFloat("Vertical", movement.y);
             animator.SetFloat("Magnitude", movement.magnitude);
     }
 }

Here is my CrossHair Script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CrossHair : MonoBehaviour
 {
     public GameObject crossHair;
     bool isAiming;
     bool endofAiming;
     Vector3 aim;
 
     void Awake()
     {
         Cursor.lockState = CursorLockMode.Locked;
         Cursor.visible = false;
     }
     void Update()
     {
         isAiming = Input.GetButton("Fire1");
         endofAiming = Input.GetButtonUp("Fire1");
         Vector3 mouseMovement = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0f);
         aim = aim + mouseMovement;
         if(aim.magnitude > 1f)
         {
             aim.Normalize();
         }
         Aim();
     }
 
     private void Aim()
     {
         Vector2 shootingDirection = new Vector2(aim.x, aim.y);
 
         if(aim.magnitude > 0.0f)
         {
             crossHair.transform.localPosition = aim * 0.3f;
             
         }
     }  
 }
 

PS:- Im Using Three Prefabs For The Slime With Each Different Color. The Slimes Spawn Randomly On The Map. Help Would Be Appreciated.

sda.png (91.7 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

112 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

2D Dash attack 0 Answers

How do I set direction of player dash movement? Currently dashes to exact mouse position. 2 Answers

I need help fixing this code 1 Answer

2d Top Down Shooter Jerky Movement 0 Answers

unity 2d platformer dash attack. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges