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 /
  • Help Room /
avatar image
0
Question by Kun-No-Name · Mar 17, 2016 at 02:59 PM · c#animationmovement

How to make orb walking?

First I have to apologize if you confuse with my word. My problem is I want to create the game that control by mouse (like diablo or path of exile). Now I can make click to walk and attack but the animation is not like I really want.

I want to control like if you click to attack but you click the floor to walk away too fast and attack's animation is not reach the limit I want then that attack is invalid.

It's like the MOBA game that you can attack and then walk to cancel ' after attack's animation ' (sorry I don't know how you call it).

Edit : I know its name. It calls " orb walking " .

I use two script to deal with this.

The First one

 using UnityEngine;
 using System.Collections;
 
 public class Phol_DamageBuffDebuff : MonoBehaviour {
 
     GameObject targetTWO;
     Animator anim;
     public bool isAttackCD = false;
     float PlayerDamage = 5f;
         
     void Start ()
     {
         anim = GetComponent<Animator>();
     }
     
     
 
     public void Attack(GameObject target)
     {
         if(!isAttackCD)
         {
             targetTWO = target;
             anim.SetInteger("PholParameter", 2);                      
             isAttackCD = true;
             Invoke("Damage", 0.6f);
             Invoke("animationReset", 1.6f);
             Invoke("isAttackReset", 1.6f);
         }
         
     }
 
     void isAttackReset()
     {
         isAttackCD = false;
     }
 
     void animationReset()
     {
         anim.SetInteger("PholParameter", 0);
     }
 
     void Damage()
     {
         targetTWO.GetComponent<EnemyScript>().DecreaseHP(PlayerDamage);
     }
 }


The second

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class Phol_MoveAnimation : MonoBehaviour {
 
     int resolution = 15;
     int CheckTargetLayer = (1<<8)|(1<<10)|(1<<11)|(1<<12)|(1<<13);
     int SearchObjectLayer = (1 << 10) | (1 << 11) | (1 << 12) | (1 << 13);
     bool isMovingPosition , isMovingObject ;
     float speed = 15 ;
     float angleRange = 90, angle = 0, range = 3, height = 1; /* การตั้งค่าของ ray ของ MovePlayerObject() */
     Vector3 TargetPosition;
     GameObject TargetObject;
     Animator anim;
     public List<GameObject> seeingObj = new List<GameObject>();
 
     void Awake()
     {
         anim = GetComponent<Animator>();
     }
 
     void Start ()
     {
         isMovingObject = false;
         isMovingPosition = false;
     }
     
     void Update ()
     {
         seeingObj.Clear();
         for (int ct1 = 0; ct1 < resolution; ct1++)
         {
             for (int ct2 = -1; ct2 <= 1; ct2 += 2)
             {
                 angle = angleRange / resolution * ct1 * ct2;
                 Ray ray = new Ray(transform.position, new Vector3(Mathf.Sin((angle + transform.eulerAngles.y) * Mathf.Deg2Rad), height, Mathf.Cos((angle + transform.eulerAngles.y) * Mathf.Deg2Rad)));
                 RaycastHit hitData;
 
                 if (Physics.Raycast(ray, out hitData, range, SearchObjectLayer))
                 {
                     if (seeingObj.Contains(hitData.collider.gameObject) == false)
                         seeingObj.Add(hitData.collider.gameObject);
                 }
             }
         }
         if (Input.GetMouseButton(0))
         {
             CheckTargetPosition();
         }
     }
 
     void FixedUpdate()
     {
         if(isMovingPosition)
         {
             MovePlayerPosition();
         }
         else if(isMovingObject)
         {
             MovePlayerObject();
         }
     }
 
     void CheckTargetPosition() /* ตรวจสอบ layer ของตำแหน่งที่กดลงไปโดยใช้ physics.raycast */
     {
         RaycastHit CheckTargetHit;
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
         if(Physics.Raycast(ray , out CheckTargetHit , 1000 , CheckTargetLayer))
         {
             if(CheckTargetHit.collider.gameObject.layer == 8) /* Ground Layer */
             {
                 if(!gameObject.GetComponent<Phol_DamageBuffDebuff>().isAttackCD)
                 {
                     isMovingObject = false;
                     TargetPosition = new Vector3(CheckTargetHit.point.x, CheckTargetHit.point.y, CheckTargetHit.point.z);
                     isMovingPosition = true;
                 }                
             }
             else /* Object-Unselect Object-Select Enemy NPC Layer */
             {
                 isMovingPosition = false;
                 TargetObject = CheckTargetHit.collider.gameObject;
                 isMovingObject = true;
             }
         }
 
     }
 
     void MovePlayerPosition()
     {
         if (Vector3.Distance(transform.position, TargetPosition) <= 1)
         {
             anim.SetInteger("PholParameter", 0);
             isMovingPosition = false;
         }
 
         else if (Vector3.Distance(transform.position, TargetPosition) > 1)
         {
             Quaternion newRotation = Quaternion.LookRotation(TargetPosition - transform.position);
 
             newRotation.x = 0f;
             newRotation.z = 0f;
 
             transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
             anim.SetInteger("PholParameter", 1);
             transform.position = Vector3.MoveTowards(transform.position, TargetPosition, speed * Time.deltaTime);
 
             Debug.DrawLine(transform.position, TargetPosition, Color.red);
         }
     }
 
     void MovePlayerObject()
     {
         
         if(seeingObj.Contains(TargetObject))
         {
             anim.SetInteger("PholParameter", 0);
             isMovingObject = false;
             if(TargetObject.tag == "Enemy")
             {
                 gameObject.GetComponent<Phol_DamageBuffDebuff>().Attack(TargetObject);
             }
         }
         else
         {
             Quaternion newRotation = Quaternion.LookRotation(TargetObject.transform.position - transform.position);
 
             newRotation.x = 0f;
             newRotation.z = 0f;
 
             transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
             anim.SetInteger("PholParameter", 1);
             transform.position = Vector3.MoveTowards(transform.position, TargetObject.transform.position, speed * Time.deltaTime);
 
         }
     }
     
 
     void OnDrawGizmos()
     {
         for (int ct1 = 0; ct1 < resolution; ct1++)
         {
             for (int ct2 = -1; ct2 <= 1; ct2 += 2)
             {
                 angle = angleRange / resolution * ct1 * ct2;
 
                 Gizmos.color = Color.yellow;
                 Gizmos.DrawRay(transform.position, range * new Vector3(Mathf.Sin((angle + transform.eulerAngles.y) * Mathf.Deg2Rad), height, Mathf.Cos((angle + transform.eulerAngles.y) * Mathf.Deg2Rad)));
 
             }
         }
     }
 
 
 
 }
 


If you want more information I will post it. Or you can just tell me which function to deal with this problem. Thanks.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

My animation is working but the character won't move. 2 Answers

Stopping an animation when key is unpressed 0 Answers

I want to stop movement of character while i call animation like Kick Jump Punch etc.. Please help 1 Answer

Switching lanes 1 Answer

Animation/Movement Error 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