I have a ball that is accelerating in the x axis, it hits a paddle, then it will bounce off and go the other way. Is there a way to make an If statement that has the condition of “If the x of the object is decreasing, then do this…”?
Here is a sample of the code I’m working with:
#pragma strict
var Player01 : Transform;
var Player02 : Transform;
var otherTransform : Transform;
function Update ()
{
var relativePoint = transform.InverseTransformPoint(otherTransform.position);
if(relativePoint.x < 0.0){//This is the IF statement I want to change
if(relativePoint.y > Player01.position.y){
if(relativePoint.x > -7){
Player01.position.y +=.09;
}
if(relativePoint.x < -7){
Player01.position.y -=.09;
}
}
else{
if(relativePoint.x > -7){
Player01.position.y -=.09;
}
if(relativePoint.x < -7){
Player01.position.y +=.09;
}
}
//Player01.position.y = relativePoint.y;
}
else{
if(relativePoint.y > Player02.position.y){
if(relativePoint.x < 7){
Player02.position.y +=.09;
}
if(relativePoint.x > 7){
Player02.position.y -=.09;
}
}
else{
if(relativePoint.x < 7){
Player02.position.y -=.09;
}
if(relativePoint.x > 7){
Player02.position.y +=.08;
}
}
//Player02.position.y = relativePoint.y;
}
}
Player 1 is paddle 1.
Player 2 is paddle 2.
Other Transform is the Ball.