
Welcome Guest
|
#1
|
||||
|
||||
|
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;http://www.geocities.com/ketchup66/flash/Movement.fla Please Advice. Thankyou ..chup |
«
Previous Thread
|
Next Thread
»
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |






