What am I doing wrong/missing?

S

sharooz

Guest
Hey Guys,

I am following "friendly cosmonauts" farming RPG tutorial and run into some strange issues(at least to me). So I am following the tutorial to about the same extend, however I seem to be missing something.

Heres my code:

Code:
// Movement Variables
input_left   = keyboard_check(vk_left);
input_right = keyboard_check(vk_right);
input_up   = keyboard_check(vk_up);
input_down   = keyboard_check(vk_down);
input_walk   = keyboard_check(vk_control);
input_run   = keyboard_check(vk_shift);

//Speed Variations
if (input_walk or input_run)    {
   spd = abs((input_walk*w_spd) - (input_run * r_spd)) ;
} else {
   spd = n_spd
}

// Reset Move Variables
moveX = 0;
moveY = 0;

// Movement Code
moveY = (input_down - input_up) * spd ;
if (moveY == 0) { moveX = (input_right - input_left) * spd ; }

y = y + moveY;
x = x + moveX;

// Collision Checks
if (place_meeting(x+moveX, y, obj_collision)) {
   moveX = 0;   
}
In friendly cosmonauts video however, she doesnt really add y = y+moveY and x = x+moveX beneath the movement code but her character still moves for some reason. If i tried to do it without, my character wouldnt move at all. I am just here up in arms wondering how her character moves but mine doesnt despite of having the identical code.

Also the collision check, I ported the same exact code but her collision works on the x axis but mine doesnt. Is there someone who can help me out?

Thanks in advance.
 
S

sharooz

Guest
if someone is interested, the video is called "Movement and Collisions" by "friendly cosmonaut".
 
maybe she is using speed or vspeed, hspeed. And direction

Code:
// Movement Variables
input_left   = keyboard_check(vk_left);
input_right = keyboard_check(vk_right);
input_up   = keyboard_check(vk_up);
input_down   = keyboard_check(vk_down);
input_walk   = keyboard_check(vk_control);
input_run   = keyboard_check(vk_shift);

//Speed Variations
if (input_walk or input_run)    {
   spd = abs((input_walk*w_spd) - (input_run * r_spd)) ;
} else {
   spd = n_spd
}

// Movement Code
hspeed = (input_down - input_up) * spd ;
if (vspeed == 0) { vspeed = (input_right - input_left) * spd ; }

// Collision Checks
if (place_meeting(x+moveX, y, obj_collision)) {
   hspeed = 0; 
}
how ever, how I would do it

Code:
var spd = 3;
hspeed = (keyboard_check(vk_right) - keyboard_check(vk_left))*spd;
vspeed = (keyboard_check(vk_down) - keyboard_check(vk_up))*spd;
hspeed *= place_meeting(x+hpseed, y, obj_collision);
vspeed *= place_meeting(x, y + vspeed, obj_collision);
good luck
 
Last edited:
S

sharooz

Guest
Oh I am sorry, I thought the previous thread was terminated due to links. Thanks for the help guys but my question was something else. I appreciate how you guys came up with different ways but I am really trying to understand her code, and why hers work and mine wont. She doesnt seem to be using hspeed nor vspeed, not that i know of after watching the tutorial.

Im just really confused. She doesnt again have x = x+moveX or y = y+moveY anywhere in the code and her movement seems to be working just fine, and so does her collision. Is something wrong with my collision code that its not working?
 
S

sharooz

Guest
thanks, here you go:

I am very sorry causing such a mess. Im just trying to understand different concepts.
 
Oh I am sorry, I thought the previous thread was terminated due to links. Thanks for the help guys but my question was something else. I appreciate how you guys came up with different ways but I am really trying to understand her code, and why hers work and mine wont. She doesnt seem to be using hspeed nor vspeed, not that i know of after watching the tutorial.

Im just really confused. She doesnt again have x = x+moveX or y = y+moveY anywhere in the code and her movement seems to be working just fine, and so does her collision. Is something wrong with my collision code that its not working?
Well, she does at the very end of the code

x += moveX;
y += moveY;

foo += 1; is the same with foo = foo + 1;

Also the collision is pixel perfect one.

If you need anything else tell me
 
Top