- Home /
Clickable area problem?
I've had a crack at making my first game.
You can see it HERE as it might give you a bit more insight in to my question.
When you click on the game case it issues the OnMouseDown function and from there I run all my little functions. Everything works ok for me.
Now people on slower computers have a problem clicking, its a little hit and miss... some times it works and some times it doesnt even if they did click it perfect.
I've also exported it to android and my super fast Nexus 10 allows me to click them fine, but a slower Galaxy 2 doesn't
I just wanted to know how would I get around this?
I played a bit with your game and also did a quick mock-up of the block rolling/falling in Unity to test was is going on. I'm running on a fast machine. If I lead the block a bit clicking in front of the block I often/usually get a hit. If I try and catch the trailing edge of the block, I usually don't get a hit even when I click on the block. I have a theory.
Between the time the block is displayed for the previous frame and the time I process the mouse click, one or more "FixedUpdate()/Physics" calculation passes have been made, moving the location of the block. So by the time you process the On$$anonymous$$ouseDown(), the visual of the block is behind the physical representation (by one frame). And the slower the machine, the slower the frames per second, and the more out of sync the visual and the physical become.
You can test this theory by significantly leading the block when you do the click/touch on a slow machine. If I'm right, you should get more hits.
If this is the problem, I'm not sure how to fix it. I have a couple of hacks in $$anonymous$$d, but I'd love to hear from someone with more experience with the physics engine.
That does sound like this could be the issue, I was going to add an extra box (not rendered) behind the game cases for "overspill", but this sadly would make the game too easy for people on fast computers...
I was hoping someone with more physics experience would comment. I can think of a bunch of untried hacks. For example, you could offset the collider back to the previous frame position until it collides. Or have a second game object with a collider of the same size. You could position it at the position in the previous fame and then do a raycast.
Your answer
Follow this Question
Related Questions
BoxCollider 2D not working OnMouseDown() 1 Answer
OnMouseDown (Collider other) Not working 1 Answer
OnDestroy collision detect 4 Answers
Activating only when mouse is held down on a button for 0.5s. 1 Answer
Collider OnMouseDown movement lag 0 Answers