LOADING
Loading
Hi , welcome back.
LogoutLOGOUT
 
  Lost password?  
Hi
 


Prev Previous Post   Next Post Next
  #1  
Old 08-18-2001, 12:43 PM
chup's Avatar
chup chup is offline
Registered User
 
Join Date: Dec 2001
Location: Temasek Island
Posts: 216
Rep Power: 12
chup is on a distinguished road
Problem with Random

I'm just to make this random movement stuff. The random code will genarate a number 1-4 and each of that number will move the object to 1 corner. here is what i have so far...

[swf x=400 y=150]http://www.geocities.com/ketchup66/flash/Movement.swf[/swf]

Problem:
After some times, all the object will move to the top left corner. It seem that the random number 2 and 3 is more popular then other. Could it be a mistake in my code?

Here is the key code:
Code:
 
CreatureX = _x;
CreatureY = _y;
if (Direction == 1) {
	CreatureY = CreatureY+Speed;
	CreatureX = CreatureX+Speed;
}
if (Direction == 2) {
	CreatureY = CreatureY+Speed;
	CreatureX = CreatureX-Speed;
}
if (Direction == 3) {
	CreatureY = CreatureY-Speed;
	CreatureX = CreatureX-Speed;
}
if (Direction == 4) {
	CreatureY = CreatureY-Speed;
	CreatureX = CreatureX+Speed;
}
if (CreatureX>390) {
	CreatureX = 390;
	Direction = (Math.random()*3)+1;
	Speed = (Math.random()*2)+1;
}
if (CreatureX<10) {
	CreatureX = 10;
	Direction = (Math.random()*3)+1;
	Speed = (Math.random()*2)+1;
}
if (CreatureY>140) {
	CreatureY = 140;
	Direction = (Math.random()*3)+1;
	Speed = (Math.random()*2)+1;
}
if (CreatureY<10) {
	CreatureY = 10;
	Direction = (Math.random()*3)+1;
	Speed = (Math.random()*2)+1;
}
DirectionChange = (Math.round(Math.random()*10));
if (DirectionChange == 1) {
	Direction = (Math.round(Math.random()*3))+1;
	Speed = (Math.round(Math.random()*2))+1;
}

_x = CreatureX;
_y = CreatureY;
Here is the link to the fla:
http://www.geocities.com/ketchup66/flash/Movement.fla

Please Advice. Thankyou

..chup
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
random movement problem kazuma Newbies 0 10-14-2006 09:16 AM
rotation with random() problem theeggman85 Game Programming 5 08-30-2006 04:39 AM
Random spinning problem. elio_vp Flash MX ActionScript 0 01-18-2006 03:25 PM
Random Motion clustering problem imm102 Flash MX 2004 4 06-13-2005 12:49 PM
Random problem FLASHIMODO Flash MX ActionScript 1 10-04-2004 12:22 PM




All times are GMT. The time now is 06:01 AM.