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 HalfBakedGames · Sep 29, 2015 at 10:34 AM · 2dmobileprogramming

Programming detection of a circle drawn in 2D space

Hi!

I'm mid-way through developing my 2D game, and can't figure this one out!

I have a player sprite attached to the touch location (I'm developing for mobile), and on movement the sprite forms a trail behind it. This trail is created by spawning in a pre-rendered line at the mid-point of delta-distance-moved between updates and is rotated to match the change in location.

Question 1. Is spawning in a pre-rendered art asset for the trail the best solution?

Secondly, I want the player to be able to create a closed loop with this trail, forming a circle. This circle will then need to be transformed into a seperate object so I can do some stuff. When the player does close the loop, they'll collide with one of the spawned trail objects, so I can detect WHEN to calculate the spawned circle, but I can't for the life of me think how I'm going to calculate what shape this circle is or how to then create a replication into the game world. All the spawned objects for the trail are stored in an array so I can access all of their locations.

To clarify, in example A below, the 5 points are in a circle, so calculating the position of x and then spawning a circle at this point is a solution. However, in example B the points are not circular, meaning that a simple circle cannot be spawned - I need to spawn in an irregular shape!

alt text

Can I create this circle with code? The shape is going to be irregular, so spawning in pre-rendered art won't work!

Thank you!

image.png (9.5 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
1

Answer by cjdev · Sep 29, 2015 at 07:28 PM

To your first question, I can't think of any other way to implement this without spawning assets and as long as there aren't more than a couple handfuls at a time you shouldn't see much of a performance hit. Also, if this player trail is a persistent thing I would definitely recommend object pooling for the spawned assets so that the overhead is even lower.

In order to calculate the shape of the trail it depends on how you are going to render the trail after you have it. Are you using a line renderer and approximating the curve as closely as possible or just spawning more objects at closer distances to each other? One way you could do it is by recording player positions regularly at much shorter intervals than the spawn points have and then using them as your points on the curve for your new shape. This way you can have an arbitrarily detailed curve by adjusting how often positions get recorded rather than just using the handful of spawn points that are far away from each other.

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 HalfBakedGames · Sep 30, 2015 at 04:44 PM 0
Share

Thank you for your reply!

As for the first question, that's quite okay, spawning assets is working good so far, just wanted confirmation that it was the best solution!

That's an interesting solution, I'll give it some thought!

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

35 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

Related Questions

Keyboard input to Mobile Input 0 Answers

Shooting Mechanic in 2D Mobile (Unity C#) 1 Answer

2d mobile Multi Scene inventory 0 Answers

Is there a way to change the play area in 2d? 0 Answers

Re sizing an object within a confined space 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