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 4illeen · Jul 18, 2011 at 07:41 PM · collisionareaoverlay

two-dimensional area overlay / collision

alt text Green short cube is moving in front of player character just above the ground - it can be rotated when holding 'q' and 'e' buttons. After mouse button 0 goes up a tall cuboid prefab is being instantiated just above the ground, with it's rotation and position equal to those of the green cube.

Green cube is just a game object with mesh - it doesn't collide with anything and has it's y position dependent on terrain height. I want to make variable private bool areaOverlay = true; whenever green cube collides with other objects such as trees, prefabs instantiated with mouse button 0, walls buildings etc, so I can make an if statement and disable the option to create new prefabs.

I was thinking of somehow checking if 2 dimensional area (x and z axis) made by four or more points is in the same space as area of other objects with certain tag/layer/script.

What's the easiest way to do it?

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
2

Answer by Rafes · Jul 18, 2011 at 08:01 PM

Colliders are probably the easiest because you can't do this calculation based on the center of an object or raycast point. You need to know if the edge of the cube is touching anything. That is, by definition a collision. You could do a raycast algorithm, but then you would still need colliders.

The only other way i can think of is to use a grid-bases system and update a 2D array so it knows where things are in the game world, like that tree, then test against it as the green cube moves. You'd probably want some sort of world scan at game start to populate the 2D array. This would probably be the way to go if you can't add colliers to everything. You would need the grid to match the cube and all objects in the world would have to obey the grid when being placed (though you can make the grid smaller, like 4 squares for the size of the cube - basically adding resolution)

Comment
Add comment · Show 2 · 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 4illeen · Jul 18, 2011 at 11:08 PM 0
Share

would you kindly tell me how to create such colliders? I tried it using some kind of tutorial but failed. Also will the green cube be still able to penetrate through those objects?

avatar image Rafes · Jul 18, 2011 at 11:35 PM 0
Share

Just add a collider component and set trigger ON. This will make it ignore physics but will still detect collisions.

A Google search yielded the following reading material. If you still have questions, please ask them!:

http://unity3d.com/support/documentation/Components/comp-DynamicsGroup.html

http://unity3d.com/support/documentation/ScriptReference/Collider.html

http://technology.blurst.com/unity-physics-trigger-collider-examples/

http://active.tutsplus.com/tutorials/unity/getting-started-with-unity-colliders-unityscript/

http://col000r.blogspot.com/2009/06/unity-triggers-and-colliders.html

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to detect if target is inside an "arc" area? 0 Answers

Want to detect if object is in grid. 1 Answer

Physics.OverlapSphere not giving proper coordinates 1 Answer

Controller area of collision/contact 0 Answers

Is OnTriggerEnter always fired when an object is already inside? 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