• 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 Inryhk · Aug 17, 2019 at 08:27 AM · pathfindingdetectionlayermask2dmovement

Inconsistent Collision detection 2D on diagonal movement?

I'm writing a roguelike where all objects move in incriments of 1 square/tile whenever a button was pressed. Here is an example of enemy moving towards a player when player is to the down-left on diagonal:

 if (target.transform.position.x < transform.position.x && target.transform.position.y < transform.position.y) //downleft
         {
             Collider2D obstacleDetection = Physics2D.OverlapCircle(checkers[5].transform.position, 0.1f, obstacle);
             Collider2D playerDetection = Physics2D.OverlapCircle(checkers[5].transform.position, 0.1f, player);
             if (obstacleDetection == null && playerDetection == null)
             {
                 newpos = new Vector2(transform.position.x - moveIncrement, transform.position.y - moveIncrement);
                 Move();
             }
             else if (obstacleDetection != null)
             {
             }
             else if (playerDetection != null)
             {
                 Debug.Log("Want to attack player up");
                 Attack();
             }
         }

I'm using 8 coliders called checkers that check all the directions around an object when they are moving. I've also made it so they are active only during a respective move attempt. Normally there are 3 outcomes, Enemy moves toward player, Enemy stops because of obstacle, enemy Attacks because there is a player next to them. However, I have this nasty bug in which whenever player stands right next to an enemy, and moves on diagonal, the Enemy not only moves with the player but also attack them at the same time. But the weird thing is: let's say player stands to the left of the enemy, when they move down-left they get hit, however when they move up-left they don't get hit... I've checked it and for whatever the reason when player is right next to an enemy and moves away on diagonal two sensors activate but only one activates when they choose the other diagonal - and it is like that for every side.

At this point I'm lost at what's causing it. I probably should just use some kind of pathfinding package or use raycast but I feel, I'm so close to figuring it out.

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

111 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

Related Questions

Enemy detection while pathfinding through the map 1 Answer

How to detect when game becomes not an active window, and when it becomes active again? 0 Answers

Make Swipe Detection Longer? 0 Answers

raycast hit not detecting && Nav mesh agent ai stealth 1 Answer

How to detect if an object is above another one 0 Answers


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