x


iPhone touch raycasting

I need help using raycast for unity iPhone. I have a game which contains a ball and a plane. The ball starts midair and gravity pushes it down. If it touches the plane, the game ends. I need help creating a script so when the player taps the ball, it bounces up. I already have the script to AddForce and make the ball bounce up, but I don't know how to create the code that activates the addforce when I tap the ball.

more ▼

asked Jun 19 '12 at 08:26 PM

KaiserDE gravatar image

KaiserDE
0 2 3 5

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Sample

Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);

RaycastHit hitInfo;

if (Physics.Raycast(ray, out hitInfo, 1000, 0))

{

  //Use hitInfo to know which object was hit...

}

This should help you, I use this to check if I tapped 3D objects.

Cheers

more ▼

answered Jun 20 '12 at 10:19 AM

Tim Michels gravatar image

Tim Michels
1.8k 8 16 20

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2505
x2001
x1535
x583
x169

asked: Jun 19 '12 at 08:26 PM

Seen: 861 times

Last Updated: Jun 20 '12 at 11:01 AM