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 sukhan2000 · Sep 15, 2019 at 09:10 PM · collisionpositionanimationclipsight

Changing Collider Position for Different Animation Clips

Hello, I am currently making a 2D topdown game. I have a character with a cone of vision- I've done this by adding a child object to the character and then putting an ontrigger collider on the child. I've made four animation clips for going up, down, left and right. I've managed to get the sprites to change for the character and cone of sight just as I want them to. However, I'm having difficulties with changing the position of the collider to match each animation clip. As you can see in the picture, when the down animation clip is running, the position of the collider does not match. This is the case for the other animation clips too. alt text

I've tried to overcome this problem by adding 4 polygon colliders (in the positions that I want them in) to the sight gameobject and enabling them depending on the direction that the character is travelling:

     public Collider2D upCollider;
     public Collider2D downCollider;
     public Collider2D leftCollider;
     public Collider2D rightCollider;
 
     Vector2 dir;
 
     void Start()
     {
         dir = GetComponentInParent<RootController>().direction;
     }
 
     void Update()
     {
         whichCollider();
     }
 
     void whichCollider()
     {
         if(dir == -Vector2.down)
         {
             upCollider.enabled = true;
             downCollider.enabled = false;
             rightCollider.enabled = false;
             leftCollider.enabled = false;
         }
         else if(dir == Vector2.down)
         {
             downCollider.enabled = true;
             upCollider.enabled = false;
             leftCollider.enabled = false;
             rightCollider.enabled = false;
         }
         else if(dir == -Vector2.right)
         {
             leftCollider.enabled = true;
             rightCollider.enabled = false;
             upCollider.enabled = false;
             downCollider.enabled = false;
         }
         else if(dir == Vector2.right)
         {
             rightCollider.enabled = true;
             leftCollider.enabled = false;
             upCollider.enabled = false;
             downCollider.enabled = false;
         }
     }

But this does not help, it only enables one polygon collider and continues the game with that same collider for all 4 animations. Any help would be highly appreciated. Thank you.

sight.png (67.0 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

182 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 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

Making Characters Sit 0 Answers

Unity 2D - MoveTowards position not updating, not recgonizing new position 1 Answer

Time when 2 objects will touch 1 Answer

How to get the central position of where an object rests on the floor(object) 1 Answer

position (vector3) of a collision. 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