September 2010
Beginner
384 pages
8h 49m
English
function Update ()
{
var halfW:float = Screen.width/2;
transform.position.x = (Input.mousePosition.x - halfW)/halfW;
var halfH:float = Screen.height/2;
transform.position.z = (Input.mousePosition.y - halfH)/halfH;
}
The two new lines of code are almost identical to the first two lines. We've created a new variable and called it halfH (half height) instead of halfW. We're changing the z property of Input.mousePosition instead of x. When you save the Script and test your game, you'll have a fully movable paddle to bounce your ball on.
Math effect
I actually put a little cheat into my code. I wanted the paddle to travel deeper and farther ...
Read now
Unlock full access