• 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 how 2 make one way obstacles in a certain order.

M

MasterOfTheYeetz

Guest
so basically I need help with making one-way obstacles that go in a set pattern like triangle, circle, square, octagon, pentagon, rectangle.
I can't find any tutorials. Call me a noob if you want, I just don't know how 2.
helpful feedback is appreciated! thanks and bye.
(btw I'm still relearning how to write code in gml, and I downloaded gms2 a week ago so...)

edit: PLZ RESPOND I NEED HELP
 
Last edited by a moderator:

Binsk

Member
Easiest way that I can think of is to split the shapes up into lines and have each line calculate the 1-way movement itself. then make your special shapes out of these lines.

Effectively what you want to do is have wall-collision code for the line but you disable it under certain circumstances. For your line you can have a variable called 'movement_direction' or something similar which represents the rough direction you want your player to be moving to be able to pass through.

When your player hits the line, check the difference between the angle of this 'movement_direction' variable and the actual direction the player is moving. You can use the function angle_difference to get you the difference between two angles between -180 and 180 degrees. How you calculate your player's direction depends on your movement code for the player. If you are using the speed and/or hspeed/vspeed variables you can use the built in variable direction. If the angle is within some threshold (let's say 90 degrees) then you exit out of the collision code, oherwise execute it as normal.

Some rough pseudo code:
Code:
// Line create:
movement_direction = 0; // Player must be moving right on the screen
movement_threshold = 90; // How many degrees off of movement_direction we still let them through the wall

// Player collision code w/ line:
var difference = angle_difference(direction, other.movement_direction); // How many angles off of the required direction are we?
if abs(difference) <= other.movement_threshold // Check if we are within acceptable bounds to go through the wall:
    exit; // If within limits, just exit the collision code 

// Do collision code here
That is the rough idea. The above code effectively would let a player go through a wall if they were moving at any angle between 0 to 90 or 270 to 360.
 
M

MasterOfTheYeetz

Guest
Easiest way that I can think of is to split the shapes up into lines and have each line calculate the 1-way movement itself. then make your special shapes out of these lines.

Effectively what you want to do is have wall-collision code for the line but you disable it under certain circumstances. For your line you can have a variable called 'movement_direction' or something similar which represents the rough direction you want your player to be moving to be able to pass through.

When your player hits the line, check the difference between the angle of this 'movement_direction' variable and the actual direction the player is moving. You can use the function angle_difference to get you the difference between two angles between -180 and 180 degrees. How you calculate your player's direction depends on your movement code for the player. If you are using the speed and/or hspeed/vspeed variables you can use the built in variable direction. If the angle is within some threshold (let's say 90 degrees) then you exit out of the collision code, oherwise execute it as normal.

Some rough pseudo code:
Code:
// Line create:
movement_direction = 0; // Player must be moving right on the screen
movement_threshold = 90; // How many degrees off of movement_direction we still let them through the wall

// Player collision code w/ line:
var difference = angle_difference(direction, other.movement_direction); // How close are we to the wall's required direction?
if abs(difference) <= other.movement_threshold // See if we are within limits to go through:
    exit;

// Do collision code here
That is the rough idea.
thank you!
 
Top