- Home /
Ray casting / Multi touch
Im new to java programming coming from a decent background in c. Im currently working on a android game where a player walks around in 3d searching for items. I have this script on my test objects to register touches
var particle : GameObject;
function Update () {
for (var touch : Touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
// Construct a ray from the current touch coordinates
var ray = Camera.main.ScreenPointToRay (touch.position);
if (Physics.Raycast (ray)) {
// Create a particle if hit
Instantiate (particle, transform.position, transform.rotation);
}
}
}
}
However while using the 3d controller prefab, when ever I touch a joystick it also registers my test objects as being touched and thus would pick up every item in my scene. I would greatly appreciate the help in how to resolve this issue.
Please, please please please please don't call javascript java. They are really quite different things. From a c background, you would probably be better served using C#, anyway...
Im in school for software development and we are focusing on java and javascript which I prefer over c any way. But thank you for your time
Answer by Graham-Dunnett · Oct 24, 2011 at 02:12 PM
Your code say "if the ray from the touch position hits any collider in the scene at all". This could include the game object used for the controller prefab. You might want to make the raycast more specific, perhaps using the second Raycast() API that returns the object the ray hit.
Your answer
Follow this Question
Related Questions
Android Drag By Steps 0 Answers
Detecting onDrag over UI images 1 Answer
Moving the camera on a touch imput 0 Answers
Android touch input 3 Answers
How to touch select 3D objects 2 Answers