STEAM GROUP
game development help gamedevhelp
STEAM GROUP
game development help gamedevhelp
4
IN-GAME
70
ONLINE
Founded
28 May, 2015
Language
English
crush 1 Feb, 2016 @ 4:49pm
Moving
I need help with this game I'm making in game maker,its a pong remake but the ball keeps going in the same direction. This is the code:

randomnum = irandom_range(1,30)
if (randomnum > 30) {
move_towards_point(obj_player,obj_player,3.0);
}

if (randomnum < 30) {
move_towards_point(obj_enemy,obj_enemy,3.0);
}

Its not even going towards a character its just going in the corner please help
< >
Showing 1-3 of 3 comments
TacoTormentor 1 Feb, 2016 @ 5:02pm 
I don't use GameMaker, but I can tell you right off the bat your randomization isn't going to work. You're generating a number between 1 and 30, inclusive, and only if that random number is larger than 30 will it move towards obj_player. It will never reach that condition. Why not just do

randomnum = irandom_range(1,2) if (randomnum == 1) { move_towards_point(obj_player,obj_player,3.0); } if (randomnum == 2) { move_towards_point(obj_enemy,obj_enemy,3.0); }
Or replace "==" with proper GameMaker syntax if it's not correct. I don't know about the going in a corner part, though.
Dworcean 22 Sep, 2017 @ 5:28am 
You got that fixed properly Taco Tormentor .. but I would suggest to combine the 2 if 's ...

like this:

...
if ( randomnum == 1 ) {
...
} else {
...
}

To fix the rest of the commands; the move_towards_point statement requires x and y coordinates
PeptoBismolDust , you can "extract" those direct from the object you want to move to by adding a point and the variable name just after the object name...

The whole routine would then be something like this;


randomnum = irandom_range(1,30)
if ( randomnum <= 1 ) {
move_towards_point( obj_player.x , obj_player.y , 3.0 );
} else {
move_towards_point( obj_enemy.x , obj_enemy.y , 3.0 );
}

crush 22 Sep, 2017 @ 6:08pm 
omg I totally forgot I programmed in Gamemaker

lol I program in unity now
< >
Showing 1-3 of 3 comments
Per page: 1530 50