# Walls gliding with gyroscope

#### Megos

##### Member
Hello!

I try to make gliding at walls with this code:

GML:
``````if place_meeting(x+1*sign(hspeed),y,oWall)
{
while !place_meeting(x+1*sign(hspeed),y,oWall)
{
vspeed = (device_get_tilt_x() * hsp);
}
vspeed=0
}

if place_meeting(x,y+1*sign(vspeed),oWall)
{
while !place_meeting(x,y+1*sign(vspeed),oWall)
{
hspeed = (device_get_tilt_y() * vsp);
}
hspeed=0
}``````
But my player only stops at wall. Could you show me an error?

#### TheouAegis

##### Member
For starters, that code is completely worthless. You are saying if there is a wall one pixel over, while there isn't a wall one pixel over, set speed along the perpendicular vector.

So get your code back to the baseline.

Code:
``````if place_meeting(x+hspeed,y+vspeed,oWall)
{
while place_meeting(x+hspeed,y,oWall)
{
hspeed-=min(abs(hspeed),1)*sign(hspeed)
}
while place_meeting(x,y+vspeed,oWall)
{
vspeed-=min(abs(vspeed),1)*sign(vspeed)
}
}``````

#### Megos

##### Member
Thank you for your help! Firstly I get code from forum and it works for keyboard. After that I changed it for gyroscope and everything goes wrong. Unfortunately with your code player stuсks at walls.

#### TheouAegis

##### Member
Post your full code for this object, not just the collision code.

#### Nidoking

##### Member
Could you show me an error?
I can show you lots of errors!

x+1*sign(hspeed)
Why would you ever multiply something by one? What purpose could that ever serve? One is the multiplicative identity.

if place_meeting(x+1*sign(hspeed),y,oWall) { while !place_meeting(x+1*sign(hspeed),y,oWall)
As has already been mentioned, this while loop will always perform exactly zero times. Which is fortunate, because
vspeed = (device_get_tilt_x() * hsp);
why are you setting vertical speed to horizontal tilt times horizontal speed? What is the possible purpose of doing this? Why would you do it in a loop? How is it supposed to help you deal with collisions? Especially since
while !place_meeting(x+1*sign(hspeed),y,oWall) { vspeed = (device_get_tilt_x() * hsp); } vspeed=0
You immediately set vspeed to zero anyway after completing the loop. The loop can never possibly have any effect even if it DID execute, aside from possibly freezing your game by being an infinite loop that fails to affect its condition in any way.

It's pretty obvious you don't understand very basic motion in Game Maker. Perhaps you need to do something simpler to learn the basic principles before you attempt to do anything complicated like this.

#### Megos

##### Member
Post your full code for this object, not just the collision code.
GML:
``````if device_get_tilt_x() < 0 or device_get_tilt_x() > 0
{
vspeed = (device_get_tilt_x() * vsp);
}

if device_get_tilt_y() < 0 or device_get_tilt_y() > 0
{
hspeed = (device_get_tilt_y() * hsp);
}

if place_meeting(x+hspeed,y+vspeed,oWall)
{
while place_meeting(x+hspeed,y,oWall)
{
hspeed-=min(abs(hspeed),1)*sign(hspeed)
}
while place_meeting(x,y+vspeed,oWall)
{
vspeed-=min(abs(vspeed),1)*sign(vspeed)
}
}``````

#### Megos

##### Member
I can show you lots of errors!
Thank you!
Why would you ever multiply something by one? What purpose could that ever serve? One is the multiplicative identity.
How I said I took it from tutorial...
As has already been mentioned, this while loop will always perform exactly zero times. Which is fortunate, because
I understand this now. I deleted "while and so on" and it's work the same.
why are you setting vertical speed to horizontal tilt times horizontal speed? What is the possible purpose of doing this? Why would you do it in a loop? How is it supposed to help you deal with collisions? Especially since
Vertical to horizontal because of landscape orientation.
You immediately set vspeed to zero anyway after completing the loop. The loop can never possibly have any effect even if it DID execute, aside from possibly freezing your game by being an infinite loop that fails to affect its condition in any way.
It's pretty obvious you don't understand very basic motion in Game Maker. Perhaps you need to do something simpler to learn the basic principles before you attempt to do anything complicated like this.
I did basics from tutorial and it works for keys but not for gyroscope. Maybe you can advice some docs for basics? I use official documentation and it's not so detailed.

#### GMWolf

##### aka fel666
How I said I took it from tutorial...
Make sure you understand all the relevant code in a tutorial before you use it.

Remember code provided in tutorials are worthless, and probably shouldn't be used as is.
The value of tutorial are in what they can teach you.
If you are copying code from a tutorial without understanding it you are not gaining anything.

#### Nidoking

##### Member
Vertical to horizontal because of landscape orientation.
Still, then, why are you using horizontal speed to set vertical speed? There's an entire subforum here for Tutorials.

#### Megos

##### Member
Still, then, why are you using horizontal speed to set vertical speed? There's an entire subforum here for Tutorials.
I use `y+1*sign(vspeed)` to get y+1 or y-1 but it's horizontal at landscape so I use hspeed after that. But right now I see that I have to use the same speed. And for all that are hspeed and vspeed belongs x and y or they changes at landscape?

#### Nidoking

##### Member
And for all that are hspeed and vspeed belongs x and y or they changes at landscape?
hspeed controls x and vspeed controls y. If you're rotating the graphics at the display, then that's a thing, but it's important to be consistent. It's confusing to use hsp to refer to vertical speed. There's also no reason to read tilt angles while processing collisions. You should be reading the control information before you do anything else, then using the stored information to compute everything else that happens in response. Like I said, tutorials. If the ones you've done don't tell you why they do the things they do, maybe you need to find more.

The latest you've posted fails to account for diagonal collisions, and I expect you'll find yourself in an infinite loop once you get stuck in a wall.