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 Runeclawmaster1 · Dec 13, 2016 at 08:55 PM · physicscolliderphysics2dcollision detectioncollider2d

How To create 2D collision detection on object which changes dimensions

Hi, Im new to Unity Development and wanted to know what the best method is to solve the problem below.

Problem: I am working in 2D and my player can fire a spear from a spear gun with a chain connected (preview included from java version below). This chain is collidable and increasing in height constantly (until it collides with something or the edge of the screen). My issue is the standard collider doesnt support directly changing its dimensions/shape once its already set and the solutions i do know of (and have implemented in java etc before) feel like hacks and usually involve messy direct handling of the box2D collider. preview

Solutions i am considering/aware of: I solved this issue in java on an older version of the game about a year ago (but never finished the game and felt unity would be better now i have the time to do it again) so i have a few solutions i can think of. some i know work in java at least (where i have direct access to the collision engine) others are less ideal backup ideas.

Solution 1: each frame in the backend code where the spear is updated, destroy its collider and create a new one of the correct size *last time i did this in box2D java it required a workaround to get it to work correctly as box2D does not detect collisions on the first update after the collider is added and as the collider will always be renewed each update it never collides, im not sure this workaround is possible/needed in unity

Solution 2: implement my own physics throughout the game. This is allot of hassle to get looking good and feels wasteful when one already exists that i should be able to work with

Solution 3: somehow create two physics systems one hand made for the spear and use unity for the rest and somehow hook into the unity collision system to integrate the two. I think this is possible from what ive seen online but ive no idea where to start with it.

Solution 4: instead of working with a single collider and changing its shape, create a chain of multiple smaller colliders and spawn them as needed. the issues with this are balancing performance and accuracy, the smaller they are the more accurate collisions will be but the simulation will then need to handle far more colliders and when the object is destroyed suddenly clear out many, many colliders all at once which im uncertain is a good idea or the colliders are larger but this creates a greater error margin during gameplay. i should note there may be more than one spear on the screen at once, eventually the game should at least be capable of many many spears being shown with little to no performance impact.

So how in unity do you solve the problem of a collider changing dimensions each frame or update? Do i use one of the above solutions? if so advice might be needed on how to even do it (i know how to do allot of these solutions when im working low level with direct access to the underlying physics system but in unity im uncertain). if not does anyone have any other suggestions/advice on how to handle it?

Thanks in advance everyone

untitled.png (52.9 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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by roblind3 · Dec 14, 2016 at 01:15 AM

So not exactly sure what you're doing to get the chain to increase length indefinitely...but I do know that you can adjust the size of the Collider with code like this: GetComponent<BoxCollider2D>().size = new Vector2(sizeX, sizeY);
That's assuming you're using a 2D Box Collider...but you can replace that any type of Collider. In another part of your code, you can set the "sizeX" and "sizeY" floats to match how long your chain has gotten. But since I don't know how you're causing the chain to extend, I'm not sure how to find your length of chain. Let me know if that helps!

Comment
Add comment · Show 1 · Share
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
avatar image Runeclawmaster1 · Dec 18, 2016 at 09:43 PM 0
Share

Thanks for that, i swear i tried this a couple years ago when i started this game and it didn't work, hadn't thought to recheck it worked.

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

123 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

Related Questions

How to make object with velocity bounce off the obstacles? 0 Answers

Physics 2D with tile collider corner problem 2 Answers

Ignore collision based on position 1 Answer

GameObject with multiple collider2D, 1 Answer

Collision check 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