This site requires JavaScript, please enable it in your browser!
Greenfoot back
JetLennit
JetLennit wrote ...

2013/4/18

Problem with a side

JetLennit JetLennit

2013/4/18

#
What is wrong with this code?
if(getX() < 2)  xSpeed = (xSpeed + xSpeed * 2);
I have this in code for a little balley thing that is supposed to bounce the other direction but instead it just does this weird thing were it is on one side then transports to the other side then transports back continually
danpost danpost

2013/4/18

#
All you are doing with this code is tripling the speed. To bounce (or move) the other direction, you need to negate the speed. You could just change the '+' to a '-', but, you should probably just say: xSpeed = -xSpeed;
JetLennit JetLennit

2013/4/18

#
Hadn't thought of directly making it a negative number with all the other ones........ but i can't believe i made that mistake!!!! Thank you sooo much
You need to login to post a reply.