- Home /
How to implement aimspot on billiard ball
Hi,
I have a white ball. When I press right mouse button blue spot should appear on the ball(aimspot). It should be possible to move this spot. What is the simplest solution in Unity? Additional texture with uv shifting?
Answer by CHPedersen · Aug 29, 2011 at 11:06 AM
A simple solution might be to attach a Projector to the tip of the cue stick, that projects a texture with a blue circle in it. The projector will take care of texturemapping the circle texture onto whatever geometry it hits. This is really easy to set up, but has a few added side-effects that you'll want to take care of:
Firstly, it'll project the aim spot onto other balls behind the cue ball if they happen to be in its line of sight, and that's definitely not what you want. You can fix that by adding the cue ball to a layer of its own, and then add everything BUT that layer to the Projector's IgnoreLayers. That way, it'll only project on the cue ball.
Secondly, it will change the size of the aimspot based on the cue tip's distance to the cue ball. That will give you a larger spot when the cue tip is far away and a small one close up, which may or may not be okay, that's up to you. If you want it to remain constant, you can change the Projector's field of view as a function of distance so that it becomes small when far away and wider when close up.
There is also a way that doesn't involve a Projector. You can do a Physics.Raycast from the cue stick's tip and forward. It returns a RaycastHit-object, that gives you a lot of useful information about the geometry it hit (the cue ball). See:
http://unity3d.com/support/documentation/ScriptReference/RaycastHit.html
Perhaps you can use the UV coordinates or the point the ray hit to position the aim spot texture.
Your answer
Follow this Question
Related Questions
Assigning UV Map to model at runtime 0 Answers
Rotating texture uv on sphere 0 Answers
Using substance and spheres, good tiling? 1 Answer
Texturing a icosphere 0 Answers
Projector on sphere creating extra lines 2 Answers