GML Need some help with code; up and side buttons have stopped working after applying collision code.

C

CreakyTeeth

Guest
Hello all,

I need some help.

Here's the code;

// Player Movement
var xMove = keyboard_check(ord("D")) && place_free(x + collisionSpeed,y) -[B] keyboard_check(ord("A")) && place_free(x - collisionSpeed,y);[/B]
var yMove = keyboard_check(ord("S")) && place_free(x, y + collisionSpeed) - [B]keyboard_check(ord("W")) && place_free(x, y - collisionSpeed);[/B]

if (xMove !=0 || yMove !=0) {
sprite_index = sPlayer;
}else{
sprite_index = sPlayer;
}
if (xMove !=0) image_xscale = xMove

x += xMove *spd
y += yMove *spd;


using GMS 2 and the code is from a video by Thomas Gervraud and Let's Learn This Together

The collision is working fine however; I'm unable to use the W and A keys to move the obj.

At first I thought I deleted something by accident; I have re-watched both video tutorials and I'm unable to find a solution to this problem.

Any help on this would be very much appreciated.

Thanks
 
Last edited by a moderator:

Nidoking

Member
Here is what you're actually checking for:

"The user is pressing D" AND "There is no collision to the right minus the user is pressing A" AND "There is no collision to the left."

All three of those conditions need to be true, in which case, your xMove is 1. If any of those three conditions are false, xMove will be 0. There is no case where xMove can be -1 because it is a boolean.

You need to use parentheses appropriately to group your checks if you want to do boolean math. I suggest that you don't attempt to do math with booleans at all, despite what the tutorials will tell you.
 

Xer0botXer0

Senpai
Holy cow what does " image_xscale = xMove " do ?

Image_xscale is between 1 and 0 sure, xMove is a true/false boolean.. I'm intrigued at how a boolean is used to set an image scale. Like is monster dead ? yes.. image_xscale 0 bish.
 
C

CreakyTeeth

Guest
Honestly.. no idea , I'm a sock puppet at this point lol

hoping to magically understand what I'm doing, the more I bury myself in tutorials.
 

Xer0botXer0

Senpai
The youtube link you shared just takes me to his homepage.
Oh right, it's between -1 and 1. o_O So kinda mirror effect by setting image_x/yscale to -1
 
Top