- Home /
Question by
shollwedel · Oct 16, 2013 at 05:18 PM ·
move an objectpong
Ball won't move to the right/left in Pong game.
Whenever I start the game the ball just moves up and down, but won't move in any direction. How can I get it to move to the right or left when the game starts?
pragma strict
var cSpeed:float = 10.0;
var sFactor:float = 10.0;
static var playerScore:int = 0;
static var enemyScore:int = 0;
function Start ()
{ rigidbody.AddForce(10,0,0); }
function Update ()
{ var cvel = rigidbody.velocity;
var tvel = cvel.normalized * cSpeed;
rigidbody.velocity = Vector3.Lerp(cvel,tvel,Time.deltaTime * sFactor);
//Check the right bounds
if(transform.position.x > 25)
{
playerScore++;
transform.position.x = 0;
transform.position.y = 0;
}
//Check the left bounds
if(transform.position.x < -25)
{
enemyScore++;
transform.position.x = 0;
transform.position.y = 0;
}
}
Comment