Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
3
Question by SrBilyon · Apr 19, 2011 at 06:24 AM · androidcollisionguivector2line

Using a screen-drawn line to check for a collision [Vectrosity]

alt text alt text

So, I have been learning some of the basics of programming for the Android, and one of the things I'm trying to find out now is how to check and see if a "drawn GUI line" (Vectrosity Line) has overlapped a 3D object and if so to count it as a collision. I also want to let the 3D object to be notified of this (Like a SendMessage)

Edit: I am now using Vectrosity to draw my lines, which is a BIG help, but now I need to use check and see if a line was drawn over a particular object on screen

Also, i'm not trying to cut anything or looking for a complex collision, i just want to see if the line overlaps a certain object.

Comment
Add comment · Show 7
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 Joshua · Apr 19, 2011 at 06:49 AM 0
Share

Before I write a lengthy answer that doesn't answer your question: with a line 'over' a 3d object do you mean that the line intersects or that the line is 'above' the object?

avatar image SrBilyon · Apr 19, 2011 at 06:52 AM 0
Share

Above. sorry should have made that clear...

avatar image SrBilyon · Apr 19, 2011 at 06:53 AM 0
Share

Like the line is traced on the object like in the diagram.

avatar image SrBilyon · Apr 19, 2011 at 12:56 PM 0
Share

Swiping/Slashing an object on screen is my intention

avatar image Eric5h5 · Apr 21, 2011 at 09:16 AM 0
Share

What exactly are you doing? Do you have basic shapes (sphere, box) that you just want to know were intersected by the line and you don't care where? Or do you have complex geometry, where you need to know exactly where the cut is? Or something else? 2D or 3D?

Show more comments

4 Replies

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

Answer by Cyb3rManiak · Apr 21, 2011 at 09:10 AM

Well, as I see it you don't really have to calculate if the line intersected the objects. Your input is the touch interface. All you have to do is check if at any time did the user moved his finger over one of the objects (unless you don't want to consider a half-way cut object as a success - in which case you'll need some math).

You can just Raycast with the help of Camera.ScreenPointToRay and get the list of objects the user touched.

I don't know how worried you are with performance, but if a raycast is too expensive for some reason, you might even try and use the OnMouseOver event. It might just work.

Comment
Add comment · Show 9 · 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 Eric5h5 · Apr 21, 2011 at 09:36 AM 2
Share

On$$anonymous$$ouseOver is just raycasting anyway (except with GUITextures), so there is no difference.

avatar image Cyb3rManiak · Apr 21, 2011 at 10:10 AM 0
Share

I imagined so, but I was never sure about it :) Thanks.

avatar image equalsequals · Apr 21, 2011 at 06:52 PM 0
Share

I built a game with this exact mechanic just last month. This method of raycasting worked like a charm.

avatar image equalsequals · Apr 21, 2011 at 06:54 PM 0
Share

Additionally, it is important to note that if the player swipes quickly and great distances across the screen, there is a chance of the target object being "skipped over" because the finger might be over the collider in between raycasts. The solution for this was to insure a high frame rate.

avatar image SrBilyon · Apr 21, 2011 at 11:17 PM 0
Share

Okay, i see what you are saying in the first part of the question. Really all I would want is a simple swipe to actually hit the object Now, Eric might understand this, but as far as I can see, the line is made up of an array of points, so what would be the simplest (as process lite) way of raycasting each point and looking for a collision of that object? Code implementation would be nice :D

I figured since I am already drawing a line, it would be best to utilize the points it generates. [For those who have vectrosity, look at the Draw Lines Touch script as a ref, that's how my line is drawn]

Show more comments
avatar image
0

Answer by StephanK · Apr 21, 2011 at 08:50 AM

I don't think there is an easy solution for this, especially if your objects have a complex geometry and you need very accurate information about where the object was slashed.

However the solution might be to calculate an "on-screen-bounding-box" for your object. To do this you could transform the vertices of your object's bounding box to ScreenSpace (using Camera.WorldToScreenPoint). That leaves you with 8 points. Now find the 4 that form the bounding box (contain the other 4 points). Now you have a rectangle. Checking if your line intersects this rectangle should be straightforward maths.

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 SrBilyon · Apr 21, 2011 at 11:11 PM 0
Share

This one seems a bit more complex than I'm looking for.

avatar image
0

Answer by Jeston · Apr 21, 2011 at 08:44 PM

I would approach this by transforming the collider of your 3d objects into screen space, and using a Line to Line collision test for each polygon in your model.

I also assume that your collision info for the line is an actual line or an array of line segments for your curvature. You can do some early logic to help the performance:ie: segment.bounds overlaps model.bounds

Comment
Add comment · 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
0

Answer by burgunfaust · Apr 23, 2011 at 03:16 AM

If you were to resort to onmouseover for your raycasting, why not use onmousedrag and just get the start and stop points?

Comment
Add comment · 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

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

1 Person is following this question.

avatar image

Related Questions

Not getting where error comes from which line when debugging on Android 1 Answer

Put an offset distance to gameobject that follows player 2 Answers

Player doesn't move as intended using touch controls 0 Answers

GUI Button for Android 1 Answer

Game Over GUI Question 2 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