Log In  

super-super alpha (near-disgustingly garbage level)
right now, it only plays the foward animation sprite

Cart #21786 | 2016-05-30 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

P#21787 2016-05-30 12:03 ( Edited 2016-05-31 13:54)

How does one solve the issue with diagonal movement being faster than vertical/horizontal?

P#21798 2016-05-30 13:13 ( Edited 2016-05-30 17:13)

to be quite honest, i'm not all too sure... i just picked up the program yesterday! :s

i can drop the lines of code that used here though, if you'd like?

P#21825 2016-05-30 15:34 ( Edited 2016-05-30 19:34)

I had similar problem while working on my pong game and I have gone into detail how I solved it over here.

When you travel diagonally on both X and Y axis at the same time, you actually travel further then if only on X or Y. This is because the diagonals in any square/rectangle are greater than any of the lengths (Diagonal "d" = √(Xsquared + Ysquared) ). So if you travel 3 pixels each tick on X and Y, diagonally you actually travel (√(33 + 33))= roughly 4.24 pixels. That's almost 125% increase!

To solve that you would need to make sure, that no matter what buttons are pressed the travel distance is the same. One way to do this is to use pythagorean theorem. You keep your distance in a variable (speed). When a single button is pressed, sprite's X or Y (depending on button) = speed (or -speed, again depending on button pressed). This is very similar to what you have right now.

When two buttons are held at the same time (one for X axis, other for Y), instead of travelling at X and Y = speed. You want X and Y equal √(speed)/2. You can implement that either with IF functions for pressing two buttons at once, or by limiting the speed variable two 3.

Hope that helps a bit. There is probably a much easier way to do it, but I am a beginner programmer myself ;)

P#21831 2016-05-30 17:13 ( Edited 2016-05-30 21:13)

You can solve diagonal movement by changing the player's velocity by a percentage if both arrow keys are held down. This allows you to scale it according to what you think feels right as you play around with it. I find that 71.5% works pretty well.

Something along the lines of

if (left and up, left and down, right and up, right and down)
  speedModifier = 0.715
else
  speedModifier = 1
end

player.vel = speed * speedModifier
P#21832 2016-05-30 18:11 ( Edited 2016-05-30 22:11)

thank you for the help, everyone!

P#21912 2016-05-31 09:54 ( Edited 2016-05-31 13:54)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-18 04:15:12 | 0.012s | Q:18