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
0
Question by ratboy · Jul 27, 2012 at 04:25 PM · physicsiosraycastframeratevectrosity

Create 'Tippex' for a drawn line.

Hello - hear me out, it sounds odd. I have a 2d physics game for IOS, where the player draws lines (made up of ink splats):

alt text

these ink splats have a script which creates a sort of continuous collider, made of many box colliders, so a 'ball' rolls smoothly down them. Now after having a few people test my game the general feedback is that rather than restarting a level if you mess up these lines, add in an eraser, i thought, since its a pen, a 'tippex' type liquid corrector is better. So, i already have vectrosity and decided to use it. I have the white line in place and you switch between pen and 'tippex' easily, and i have layered it so it sees and removes the inks and colliders when over it, but it misses a few, due to the speed of update. I then put it in to fixed update so it raycasts more, but it still misses a couple. So i need to know, is there a better way to check if the touch position hits one of these colliders - ie not using raycasts,, as fixed update isnt fast enough. And if not, any ideas how to go about upping the framerate? ive optimised the game already, rigorously, so im a bit stuck.

Tippex line :

alt text

(basic test line, need to smooth it etc)

PS. sorry about the essay, but i know its better to have too much detail than too little.

screen shot 2012-07-27 at 17.16.50.png (17.5 kB)
screen shot 2012-07-27 at 17.24.33.png (8.4 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

Answer by whydoidoit · Jul 27, 2012 at 06:48 PM

So you won't fix it by using a different frame rate - there's always going to be a case where it misses. It sounds to me line you need to ray cast from the previous position of the line in the last Update to the current position making sure that such a line would intersect the plane on which the ink spots exist. You might also cast a sphere rather than a line to make sure that the width of the tippex brush is simulated.

Comment
Add comment · Show 4 · 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 ratboy · Jul 29, 2012 at 01:27 PM 0
Share

thank you for your reply, agreed. This makes much more sense.

Ive tried making the spherecast work and im going wrong somewhere, do you think you could have a quick look? much appreciated if so.

function FixedUpdate(){ if (hudScript.tipexOn){ if (Input.touchCount == 1){ thisPos = Input.touches[0].position; Debug.Log(thisPos); if (Physics.SphereCast(lastPos, 1.0, (lastPos-thisPos).normalized, hit, Vector3.Distance(thisPos, lastPos))){ if (hit.collider.name == "InkCol"){ hitInk = hit.collider.gameObject; Destroy(hitInk); Debug.Log(hitInk); } } lastPos = thisPos; } } }

the code stops at if(Physics.Spherecast)... im obviously missing something extremely stupid, so i think its time to ask for help.

thanks again.

avatar image whydoidoit · Jul 29, 2012 at 01:57 PM 0
Share

One thing - it's not a good idea to do input in FixedUpdate as depending on the computer and the frame rate inputs can be missed or doubled up - Update is the right place for this code.

Otherwise my concern would be that the 0 z position of a screen touch doesn't intersect with where you plot the inkspots (are they at z=0) - we should probably be converting those touch positions before the cast to fit world space. Normally that would be using Camera.main.ScreenToWorldPoint where we'd specify the z coordinate that was appropriate.

avatar image ratboy · Jul 29, 2012 at 02:13 PM 0
Share

so something like this then..

var ray = Camera.main.ScreenToWorldPoint (lastPos); if (Physics.SphereCast(ray, 1.0, (lastPos-thisPos).normalized, hit, Vector3.Distance(thisPos, lastPos))){

(would obviously test myself but not at the mac right now) :)

oh and thanks for the pointer, will stick it in Update.

avatar image whydoidoit · Jul 29, 2012 at 02:45 PM 0
Share

Yes, normally you would also specify a z position in world units from the camera.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Drag Rigidbody Script lags on IOS device? 1 Answer

Passing values from Shader to C# script 0 Answers

Raycasting 1000 times 1 Answer

Make a rolling ball always on ground without falling when reaching the edges of the map 1 Answer

Make Ray hit own collider 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