• 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!

Legacy GM Slope Glitch.

D

Dopaminestudios

Guest
I have employed raycasting to create dynamic slope detection for my player. There is right now 2 sensor objects one placed at the players x+9 and another at the players x-9. The players y position is determined by these dots that use the rays to make sure they are always 20 pixels above the ground. There is also a script that changes quadrant when it reaches a certain angle.

Quadrant 1 is from 315 degrees to 359 and is from 0 degrees to 45 degrees (Ground level)
Quadrant 2 is from greater than 45 degrees to 135 degrees (Right Wall level)

For Quadrant two all i did was make the rays move right so it will be x+i not y+i and the sensors lock to an x position

//Raycasting in both sensor objects. Quadrant 1
for(i=0;i<=25;i++){
if place_meeting(x,y+i,obj_ground){
break;
}
}

Im just going to show sensorA but anywhere you see global.apos for the other sensor it's global.bpos

These following lines keep the sensors twenty pixels above the ground

global.apos = i

if global.apos > 20{
difference = global.apos -20
y += difference
}

if global.apos < 20{
difference = 20 - global.apos
y -= difference
}

The player is moved along x (or y if it is quadrant two)

global.angle = point_direction(obj_sensorB.x,obj_sensorB.y,obj_sensorA.x,obj_sensorA.y)


This following lines of code just generate a constant
if global.apos = global.bpos {
if quadrant = 1{
global.angle = 0
}
if quadrant = 2{
global.angle = 90
}
}

Movement xsp is just my movement physics variable

if quadrant = 1 {
x += cos(degtorad(global.angle))*xsp
}
if quadrant = 2 {
y -= sin(degtorad(global.angle))*xsp
}

Okay so now after that explanation let me explain my problem. This code works great for going up a slope moving right and going down a slope moving right. Also it work well for moving up a slope moving right. But when ever I try to go down a slope moving left the player begins to glitch when it reaches its 45 degrees quadrant shift and will not allow the player to progress past that point. I'm not sure what is causing this.
 
Top