PDA

View Full Version : [AS2] Random movment


Keensta1
04-22-2009, 04:56 PM
Hi im making a little game to show some mates how to use actionscript.

Im ok at it. Im making a simple moving game and you have to collect a sqaure to get 1 point i have point thing up a running.

So heres rhe problum Im using a hittest for the ball to hit the point object (i refer to i as point because its instent name is Point).

so i have all the movement for the ball.

I entered this code after all the code and placed at the end.

if (_root.Point.hittest(_x, _y, true)){
score++;
_root.Point._x= Math.random(530)+25
_root.Point._y= Math.random(650)+25


Thats the code it works. Also that off the top of my head. So i tested it and it worked but after hiting it once it moves to a diffrent place fine so i go get it again and notice it moving but back to the same place.

I asked my teacher He great at it he said theres a code you can put there so it proper random ( he said he just cant think what it is) and does not like go to _x=100 _y=100 like for every.
I want it so it changes the _x and _y changes every time.

That code works just after once its touched first it work but second it stays in the same place all the time.

So if you have the code for the bit to make it so the math.random is totaly random would be great if you could write the whole hit test bit.

Keensta1
04-22-2009, 05:31 PM
I Posted this some time ago and still no responce i was wondering why some other one posted later then i posted mine and has all reday had 8 replies. Why hasent mine replyed to yet i under stand it takes time but thats just weird if he got posted on first

crosshair
04-22-2009, 05:36 PM
Try this:

_root.Point._x = Math.ceil(Math.random() * Stage.width)
_root.Point._y = Math.ceil(Math.random() * Stage.height)

Keensta1
04-23-2009, 07:07 AM
Try this:

_root.Point._x = Math.ceil(Math.random() * Stage.width)
_root.Point._y = Math.ceil(Math.random() * Stage.height)


Ok i try this once i have accress to the flash file im working on. I post what happenes

Keensta1
04-23-2009, 10:41 PM
I try it didnt work but i finnly got it.