A
Arsenio delacruz
Guest
so i was coding the movement for my player and i ran in to a weird problem
if (right) {hspd = 5}
else if (left) {hspd = -5}
if (!right) || (!left) {hspd = 0}
x += hspd
this was the original code that i had when i first was making my movement code. when i went to run the game tho the player object would not move at all unless i press both the left key and the right key at the same time and would only move to the right.
after i look at the code i tried switching the code to this
if (right) {hspd = 5}
else if (left) {hspd = -5}
if (!right) && (!left) {hspd = 0}
x += hspd
after the change the player was able to move left and and right. the thing is i am not sure why.
if (right) {hspd = 5}
else if (left) {hspd = -5}
if (!right) || (!left) {hspd = 0}
x += hspd
this was the original code that i had when i first was making my movement code. when i went to run the game tho the player object would not move at all unless i press both the left key and the right key at the same time and would only move to the right.
after i look at the code i tried switching the code to this
if (right) {hspd = 5}
else if (left) {hspd = -5}
if (!right) && (!left) {hspd = 0}
x += hspd
after the change the player was able to move left and and right. the thing is i am not sure why.