Log In  
Log In  

Cart [#55294#] | Code | 2018-08-17 | No License | Embed

This cart outlines a fairly simple way in which diagonal vectors can be normalized, to avoid super-fast diagonal movement. On tab 0, you can check out the normalization code, and an example of where you should drop it in your code to make it work!

Feel free to use this function in your code, or to revise the math to make a more efficient system! The movement is a little jittery, so there's definitely room for improvement!

Also ... Vector the Skateboarding Duck might feature in future games. We'll see!

P#55295 2018-08-16 23:10 ( Edited 2018-08-17 13:59)

:: dw817

Interesting. Player is penalized for moving diagonally and does not move as fast if just up, down, left, or right.

That should add challenge to a skater game !

P#55300 2018-08-16 23:59 ( Edited 2018-08-17 03:59)
:: eggnog

@dw817 - Oh, it's not meant to penalize!

Say you want to cap your player's movement at 2 pixels per frame. Without normalizing, your player can move 2px vertically, 2px horizontally, and 2.8px diagonally. This code caps the diagonal movement at 2px, so movement in all directions is more-or-less the same pace!

P#55320 2018-08-17 09:59 ( Edited 2018-08-17 13:59)

[Please log in to post a comment]

X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2019-03-20 15:05 | 0.133s | 4194k | Q:27