|
-
Ball - Moving 90 Degrees
Hey again guys
I know the title seems a bit simplistic but thats the trouble Im having. Its not that I cant do it - because I can, but the problem lies with not going directly 90 degrees
Ill explain what I mean and give you the .fla to see for yourself
I have this ball which I want to move in one direction by itself. It will keep moving in this direction until it makes contact with the movie clip 'boundary'.
If the hittest is true then the ball will then rotate 90 degrees, and will continue to do so on and on and on
Now the problem (actually two when I think about it):
I used pretty much the same code I did for mine and Ostils cargame (theres a thread in this forum) and just modified it to work the way I needed it to.
1) The first problem is that the ball doesnt turn a perfect 90 degrees mathematically, it just looks like it does. This is a problem because if you let it run, eventually the ball will go on angles and such
2) When the ball hits the wall, it gives a slight bounce back, and thats a problem when it hits near a corner because it will bounce back and hit the other wall (sort of hard to explain but you can see for yourself)
So yea, if someone could help me out with this, by showing me what Im doing wrong and how to take the bounce of my hittests it would be appreciated 
The code is in the ball movieclip - *attaches file*
Thanks guys
Last edited by Osteel; 05-01-2009 at 02:39 AM.
-
Style Through Simplicity
I cant see too much of a problem, i didnt notice the first one you said about at all. The second problem is because you are allowing the ball to move too far into the walls, so as soon as it turns, it needs to turn again. You need to write a function that will move it back the right ammount so that its just toutching the wall (or at least make it move back far enough so it no longer thinks its hitting the wall).
Ali
-
M.D.
code:
onClipEvent (enterFrame) {
speed += 1;
speed *= .90;
x = Math.sin(_rotation*(Math.PI/180))*speed;
y = Math.cos(_rotation*(Math.PI/180))*(speed*-1);
if (!_root.boundary.hitTest(_x+x, _y+y, true)) {
_x += x;
_y += y;
} else {
_rotation += 90;
}
}
Your ball bounced back because you were inverting the speed. Also there's no need to position the ball if it hits a wall, unless you are checking for 4 point collision, in this case your not. You'll just end up with errors, because sometimes your checking the wrong direction.
Hope it helps
Last edited by mr_malee; 10-17-2005 at 12:22 PM.
-
Style Through Simplicity
Somthing like this...
Its not great, you could do it in far better ways than this, but this is a quick solution. I also changed your trig a lil bit, just makes it a bit more like the usual method.
Ali
[EDIT]
or just use that ^^ lol.
Last edited by alillm; 10-05-2007 at 08:19 AM.
-
-
Style Through Simplicity
-
Haha yea
Well Ill see which best suits me and Ostil's (yes were doing another game together haha) needs, but I really appreciate that you were both willing to help
Ill be sure to post up the completed one if and when its done
-
Thanks guys
Making games I think is the best way to learn flash =P
-Ostil-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|