• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML (SOLVED) Having trouble writing collisions for a movement code

E

Ezeeskillz

Guest
I am currently using the dual stick code from this video:

I cannot for the life of me figure out how to get collisions to work with this. The movement code is:

//GAMEPAD L-STICK MOVEMENT
if gamepad_axis_value(0,gp_axislv) >= -deadzone_limit && gamepad_axis_value(0,gp_axislv) <= deadzone_limit
&& gamepad_axis_value(0,gp_axislh) >= -deadzone_limit && gamepad_axis_value(0,gp_axislh) <= deadzone_limit
{
image_angle = direction;
speed = 0;
}
else
{
var hlaxis = gamepad_axis_value(0, gp_axislh);
var vlaxis = gamepad_axis_value(0, gp_axislv);
direction = point_direction(0, 0, hlaxis, vlaxis);
speed = point_distance(0 ,0, hlaxis, vlaxis) * player_speed;
}


Can anyone help me out with this or is there a better way to do the movement code in general.

Thanks!
 
That code's heftier than it needs to be. Store the axis returns in variables so you aren't calling the same functions several times, store the distance in another variable, and only update the direction and movement if the distance is greater than the deadzone limit.

What collision code have you attempted?
 
E

Ezeeskillz

Guest
So I altered the code a bit to be closer to Shaun Spaulding's code as it's much easier to follow and edit. Here is what I currently have:

CREATE EVENT

hsp = 0;

vsp = 0;

movespeed = 4;


STEP EVENT


//GET PLAYER INPUT

moveLeft = (gamepad_axis_value(0, gp_axislh) < 0)

moveRight = (gamepad_axis_value(0, gp_axislh) > 0)

moveUp = (gamepad_axis_value(0, gp_axislv) <0)

moveDown = (gamepad_axis_value(0, gp_axislv) >0)


//REACT TO PLAYER INPUT

horMove = moveLeft + moveRight

vertMove = moveUp + moveDown


hsp = horMove * moveSpeed

vsp = vertMove * moveSpeed


if (place_meeting(x+hsp,y,obj_wall))

{

while(!place_meeting(x+sign,y,obj_wall))

{

x += sign(hsp);

}

hsp = 0;

}



if (place_meeting(x,y+vsp,obj_wall))

{

while(!place_meeting(x,y+sign(vsp),obj_wall))

{

y += sign(vsp);

}

vsp = 0;

}



//APPLY HSP AND VSP VALUES TO X & Y COORDINATES

x += hsp;

y += vsp;


However I am receiving the following errors when running the game:



In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : cannot use function/script name for a variable, using "sign"
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : Symbol ) expected
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : wrong number of arguments for function place_meeting
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : Symbol ) expected
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : unexpected symbol "," in expression
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : malformed assignment
In Object conPlayer, in Event StepNormalEvent action number 1 at line 15 : malformed while statement
Compile Failed - Please check the Compile window for any additional information

I don't understand what I am missing about why this collision code will not work for the movement code.
 

Slyddar

Member
Hopefully you've solved it yourself, which is what BattleRifle is trying to get you to do, and is always the best way rather then us tell you, but if you are struggling I've included some more help below.
while(!place_meeting(x+sign,y,obj_wall))
When you use sign you are getting the sign of a value, which will be either -1 or +1. 'x+sign' should be 'x+sign(hsp)'.
 
Last edited:

TheouAegis

Member
It's x+sign(hsp) that he typoed on.

Also moveLeft needs to be negated or you need to change horMove to horMove=moveRight-moveLeft.
 
E

Ezeeskillz

Guest
I got it without the spoiler from TheSly. I just went back and looked at what was different about this collision code than the same ones I've used in the past and found it. I was just brain dead after a long session.

Got it all fixed after I took a look at it again after getting some sleep.

Thanks for all your help though!! I appreciate the nudge to get me to work it out instead of just feeding me answers too.
 
Top