How to fix your diagonal movement!

  Рет қаралды 2,784,408

Challacade

Challacade

Күн бұрын

Diagonal movement may be easy to implement, but you might want to consider normalizing your vectors.
#gamedev #shorts

Пікірлер: 1 900
@heartofdawnlight
@heartofdawnlight 10 ай бұрын
speedrunners hate this one programming technique
@-Yello-
@-Yello- 9 ай бұрын
I was thinkin the same thing lol
@729MendicantTide
@729MendicantTide 9 ай бұрын
Goldeneye players too
@ollllj
@ollllj 9 ай бұрын
we need a list of 3d games, that fail to normalize some movement vectors.
@danolantern6030
@danolantern6030 9 ай бұрын
Speedrunners when not every single little exploit is kept in for them and not every little aspect of a game is designed around them
@porkt3887
@porkt3887 9 ай бұрын
​​@@danolantern6030lol games usually arent designed around speedruns but devs may choose to leave in some bugs runners use. Like ocarina of time 3d they left in super slides but fixed but the buggy crouch poke. now modern zelda games they fix all the fun bugs before any of the game breaking stuff lol
@MrSirSquishy
@MrSirSquishy 5 ай бұрын
Sometimes its actually better to leave this in as a "bug but actually feature" since it can help make walking less monotonous for certain players, as strafing can keep things feeling active.
@onegoesdown
@onegoesdown 3 ай бұрын
This is such an important thing. So many devs lost this mindset.
@mchlkpng
@mchlkpng 3 ай бұрын
I tried normalizing movement for something. It really didn't feel right. Even if you're going the same speed, it feels slower
@anonymousapproximation8549
@anonymousapproximation8549 2 ай бұрын
​@@mchlkpngBecause you basically are. You're not going forwards as fast, nor are you moving to the side as fast.
@mchlkpng
@mchlkpng 2 ай бұрын
@@anonymousapproximation8549 true
@marcxworld5708
@marcxworld5708 Ай бұрын
Nah its not better lol
@rory8182
@rory8182 10 ай бұрын
This is why they move diagonally in original Doom speedruns
@Kushibunny
@Kushibunny 9 ай бұрын
Doesn't count for the fact that you run SIGNIFICANTLY faster by running diagonal along a wall in Doom/Doom 2. That's just a straight up bug.
@platinumfactor
@platinumfactor 9 ай бұрын
That's not true. The actual reason for that is that all directions of movement max out at Speed 40. However, a glitch that allows you to move and strafe in the same direction simultaneously can give you a speed of value of SR50 or SL50 (Strafe Right 50 or Strafe Left 50) It's only faster than running on long stretches where you can do it for long enough. That's why they'll usually just run forward or to the direction of the next objective if they're in a small room.
@wileecoyotegenius5955
@wileecoyotegenius5955 9 ай бұрын
And Goldeneye
@threeco2350
@threeco2350 9 ай бұрын
​@@platinumfactoryes, a good example of the movement shown in this video would be diablo 1.
@TF2Starlight
@TF2Starlight 9 ай бұрын
@@platinumfactoryea you can run along a wall and run faster…
@Casual330
@Casual330 Ай бұрын
Running in zig-zags never made more sense
@motc8238
@motc8238 25 күн бұрын
let's say you're going right, whether you go up or down as you go right, in this scenario you'd still only move right at the same speed.
@SalimShahdiOff
@SalimShahdiOff 18 күн бұрын
Still doesn't make send
@radialmachinery9947
@radialmachinery9947 17 күн бұрын
​@@motc8238But if you want to just say go forward if you keep holding right you would end up completely wrong
@coco13579
@coco13579 13 күн бұрын
​@@motc8238 actually, you'd be going a lot slower becaused the horizontal speed is less than the total speed, instead of being equal like if you went straight
@trifortay
@trifortay 6 күн бұрын
running in a zigzag wouldn't increase you're vertical velocity.
@thelred-ph3lq
@thelred-ph3lq Жыл бұрын
Note to self: When escaping from danger run diagonally. Those straight line runners will have a hell of a time trying to catch up.
@meteylmaz4366
@meteylmaz4366 Жыл бұрын
Remember, you don’t need to outrun the monster. Just outrun your friends!
@ChronoNewton
@ChronoNewton Жыл бұрын
lmao🤣🤣
@ultra-doggofn9788
@ultra-doggofn9788 10 ай бұрын
😂😂
@GunSpyEnthusiast
@GunSpyEnthusiast 9 ай бұрын
@@meteylmaz4366 note to self, run at an angle which you can run directly to your friend to clothesline them, whilst moving diagonally.
@Sjorsje
@Sjorsje 9 ай бұрын
The World is not Enough on N64 in a nutshell
@glltyt
@glltyt 2 жыл бұрын
This is the first time I've ever understood the relation between the game math and the result. Thank you so much.
@ravihlb
@ravihlb 9 ай бұрын
Same!
@hikari1690
@hikari1690 9 ай бұрын
I just clicky cause I wanty. Sides, could use polar coordinates instead of this Kardashian coordinates and save some computing power 🤣
9 ай бұрын
​@@hikari1690That would work, but wouldn't save any computing power.
@squishyushi
@squishyushi 9 ай бұрын
Big brain
@clumsypanda7433
@clumsypanda7433 9 ай бұрын
​@@hikari1690Cartesian*. Kardashian coordinates would be used to measure amount of plastic in a bimbo
@Xeno_Solarus
@Xeno_Solarus 9 ай бұрын
Bro the Xenoblade music! Mad respect.
@GugureSux
@GugureSux Жыл бұрын
The first time I noticed this was back in the N64 days, playing Goldeneye 007. Diagonal movement was a legit tactic I used to speedrun missions.
@vulkanosaure
@vulkanosaure Жыл бұрын
It's incredible that they didn't fix this though. N64 was already an advanced time compared to the NES / snes era, and this diagonal problem is a well known one
@yapflipthegrunt4687
@yapflipthegrunt4687 9 ай бұрын
Looking down to run the game at a constant 60fps is another speedrun strat for that game.
@19Szabolcs91
@19Szabolcs91 9 ай бұрын
Pretty surprising to see this issue pop up even in more recent games. There is this indie Super Monkey Ball tribute game called Paperball which does the exact same thing, no vector normalization, so diagonal movements are simply faster. I know it's an indie game, but otherwise pretty well made, and it's so recent...
@RipVanFish09
@RipVanFish09 9 ай бұрын
A fun side effect of having all of those different and weird control schemes is that some of them had a genuine advantage over the others, because of funky programming. :P
@skad2058
@skad2058 9 ай бұрын
​@@vulkanosaureMy guess is it's a video game where the player is bounded to the square of the map Like, you can't just move quite a bit, you have to go from a square to another It's not possible to fix diagonal walk in those game, it would make the player stand between the squares, which would break the game
@stellar7933
@stellar7933 Жыл бұрын
Love how algebra actually becomes so helpful when you get into programming
@janpapai9205
@janpapai9205 10 ай бұрын
Its kinda more linear geometrics then algebra bc the formula is about a triangle and its sides but nevermind
@madscientist14
@madscientist14 10 ай бұрын
dude you started learning algebra at 1st grade. trying to find out the answer to 1+1=x is algebra. I'm pretty sure you've used it in a lot of ways in your life now.
@bigfatpandalaktana2747
@bigfatpandalaktana2747 9 ай бұрын
Welcome to engineering - where we actually use the maths we were taught in school
@aBucketOfPuppies
@aBucketOfPuppies 9 ай бұрын
I laugh when I think back to all the kids who thought that math was useless because they just wanted to become programmers
@saechaol
@saechaol 9 ай бұрын
especially when you take linear algebra and it’s basically fundamental to computing graphics and games
@zants_
@zants_ 9 ай бұрын
I never realized why diagonal movement was so uncanny, this was so helpful
@raya-fantasia
@raya-fantasia 9 ай бұрын
As the artist of an indie team, I really want that guy to have diagonal animations
@raya-fantasia
@raya-fantasia 9 ай бұрын
👍
@caldercockatoo2234
@caldercockatoo2234 9 ай бұрын
@@raya-fantasiaWhy’d you reply to your one comment?
@raya-fantasia
@raya-fantasia 9 ай бұрын
Someone else commented before, but I think they deleted it
@why_i_game
@why_i_game 9 ай бұрын
@@raya-fantasia Lol, people deleting their comment just to make you look a bit crazy. It's sort of like when a tonne of people upvote a comment... then the person changes the comment to something absurd, and you're like "why are so many people upvoting such a stupid comment?"
@raya-fantasia
@raya-fantasia 9 ай бұрын
yes
@varglbargl
@varglbargl 6 ай бұрын
normalizing diagonal movement alone would knock this pixel art character out of alignment with the pixel grid.
@juhmop
@juhmop 8 ай бұрын
never thought the pythagorean theorem would be useful in any way possible
@errantcondor9349
@errantcondor9349 10 ай бұрын
I could swear I heard Colony 9 in the background. I love you.
@gavinli1368
@gavinli1368 10 ай бұрын
Yeah!!! Xenoblade OST fans! Escoecially the night time theme!!!
@waltercardcollector
@waltercardcollector 9 ай бұрын
Yess! Colony 9 night music is one of my favorite video game music pieces of all time.
@pedrobeckup456
@pedrobeckup456 9 ай бұрын
I love this song!!
@Betsy7Cat
@Betsy7Cat 9 ай бұрын
@@gavinli1368I recognized it right away bc it’s one of like 5 songs from the game I use to fall asleep lmao
@Sharklady594
@Sharklady594 8 ай бұрын
I immediately knew it was a xenoblade song I just didn’t know which one, thank you
@vulpinitemplar5036
@vulpinitemplar5036 9 ай бұрын
I've known how to fix it for a while but I hate how sluggish it ends up feeling as a result, it's got that cursed vibe.
@TheEuropeMan
@TheEuropeMan 9 ай бұрын
Speedrunners want to know your location
@GlitchedBlox
@GlitchedBlox 8 ай бұрын
Pythagorean Theorem, my beloved.
@James2210
@James2210 6 ай бұрын
This fix is why walking diagonally into walls cuts your speed by ~30%.
@linksword7110
@linksword7110 2 жыл бұрын
For anyone wondering how the code works local vec = vector(dirX, dirY):normalized() * player.speed player:setLinearVelocity(vec.x, vec.y) DirX and DirY are either 1, 0 or -1 depending on which direction he goes The code is grabbed from his Zelda game
@agent-33
@agent-33 2 жыл бұрын
Thanks. It's a shame the uploader didn't give the actual answer and just "blah blah got it? ok bye" to us.
@alessioturco953
@alessioturco953 2 жыл бұрын
where shoul i copy it? in fuction load or update
@pyrytheburger3869
@pyrytheburger3869 2 жыл бұрын
@@alessioturco953 update probably
@linksword7110
@linksword7110 2 жыл бұрын
i would recommend learning how normalization works with math.
@tofame4291
@tofame4291 Жыл бұрын
@@pyrytheburger3869 the reason for that was probably that he barely fit in one minute lenght of the video (which is a short). I might be wrong, but I guess that if he added explanation it would cross the "limit". Neverthless, quite bad that he didn't pin the answer (the one above) or write his own. Btw, I know this was 9 months ago xD
@jpslr-86
@jpslr-86 8 ай бұрын
Damn i finally understand what normalizing a vector means
@tiger_vii
@tiger_vii Жыл бұрын
I can't believe I fell asleep during maths classes..... Damn it!
@zaplershorts7783
@zaplershorts7783 Жыл бұрын
Ik I’m late at answering but, I did too 😅
@erikblaas5826
@erikblaas5826 Жыл бұрын
Math is very dry stuff most of the time, and very exousting to take attention to. ( english is not my primar language, sorry for errors)
@ClodsireBcuzYes
@ClodsireBcuzYes 10 ай бұрын
nah its not ur fault, they make it as boring as one could imagine
@theoriginaldrdust
@theoriginaldrdust 8 ай бұрын
im happy that now (im at the very end of gen z) at least in australia them highschool teachers make maths interesting if not sufferable
@tiger_vii
@tiger_vii 8 ай бұрын
@@zaplershorts7783 were u still sleeping
@KettleClogScratch
@KettleClogScratch Жыл бұрын
I'm working on a top down adventure game and this actually helped fix my diagonal movenment. Thanks!
@brodyfishel5579
@brodyfishel5579 Жыл бұрын
Which engine are you using?
@maddenmartin7436
@maddenmartin7436 8 ай бұрын
math and physics all in one for such a simple part of a game lol
@alexatedw
@alexatedw Жыл бұрын
Excellent use of the short content for programming.
@seeyainvalhalla8702
@seeyainvalhalla8702 7 ай бұрын
When I was in the primary school I always thought that vectors are useless, now I see I was wrong
@justaway_of_the_samurai
@justaway_of_the_samurai 9 ай бұрын
It also applies to movements in 3 dimensions in 3D games. If you move forward 1 unit, to the right 1 unit, and up 1 unit, the total magnitude of your movement will be equal to the square root of 3 (about 1.73), as compared to the 2D diagonal movement example here , which is the square root of 2 (about 1.41). This even applies to movements in theoretical 4D dimensions and beyond.
@10_days_till_xmas
@10_days_till_xmas 9 ай бұрын
In 3D games, up velocity is usually done separately, bc of gravity, and u can’t add continuous velocity when jumping, so the jump strength is balanced around the jump height. Ofc space games are different tho
@acebandge5293
@acebandge5293 9 ай бұрын
Coming from an avid OW2 nerd, you just helped me understand faster flying character's movement tech. Specifially, Echo's mainmovement ability lets her fly vertically while holding the a diagonal movement combination. This is just better to do as Echo when flying (which is what her thing is.) Now, mathematically, I will, be the Echo Diff, if not in frags; then at least in quicker fly speed velocity.
@justaway_of_the_samurai
@justaway_of_the_samurai 9 ай бұрын
@@10_days_till_xmas Yeah typically character movement in 3D videogames would not be utilizing all 3 dimensions in the same way, so it is more like 2D movement in that regard. But it still applies to other use-cases outside of the main character's movements, such as with flying enemies, particles, and perhaps scenery.
@why_i_game
@why_i_game 9 ай бұрын
@@10_days_till_xmas This made me think of flying around in Descent bumping into walls. It was the first game I played with fully 3D movement (up, down, rotation, rolling, etc.) and it got really confusing at times!
@nickpatella1525
@nickpatella1525 8 ай бұрын
This very much applies to 4D games, where the ground is 3D, meaning you need to normalize a 3D movement vector.
@BlizV2
@BlizV2 8 күн бұрын
First time math classes actually helped me 😭
@mohamedmoh5789
@mohamedmoh5789 2 жыл бұрын
I love how you explain these concepts generally without specifying a game engine this help different game engine users to apply these cocepts according to game engine that they're using
@jesusofbullets
@jesusofbullets 9 ай бұрын
It’s crazy how many major video games don’t understand this simple concept. Halo 3 even, for example, you travel significantly faster diagonally while using a ripped off chain gun or missile launcher than you do when moving forwards or backwards
@Eddman368
@Eddman368 10 ай бұрын
This also explains why in older games like Doom you move faster diagonally
@giow1546
@giow1546 5 ай бұрын
It's funny that this even happens in famous games like Chrono Trigger
@iuPeepleAnimations
@iuPeepleAnimations 13 күн бұрын
"Normalise the Vector" Me: "OH YEAH!"
@KIRBOFLURBO
@KIRBOFLURBO 10 ай бұрын
Ah, the xenoblade music fits in so many peaceful places
@missus_chan
@missus_chan 8 ай бұрын
Normal players: Go straight Speedrunners: WWWWWWWW
@AacatNet
@AacatNet 9 ай бұрын
Normalizing the vector is good for 3D games but when I developed my game, the diagonals felt slower despite it moving the same speed. So I made it 1.2x faster for diagonals on purpose and no one noticed in testing because it felt more normal than actually normalizing.
@Muho_is_me
@Muho_is_me 9 ай бұрын
Thats probobly becouse the screen will move slower when you are still holding the same key since you cant move camera around to abuse fastness of it like in 3D games id say its a good idea to keep it fast like you did
@duncathan_salt
@duncathan_salt 9 ай бұрын
little cheats like this are often necessary for things to feel good. it's particularly useful when running up slopes - players rarely want the physics to be realistic in that case, since it only slows them down
@hugoguh1
@hugoguh1 9 ай бұрын
The thing about normalizing is that while you move at the same speed in the diagonal direction, you lose speed in the vertical or horizontal direction which discourages you to have a little fun when moving from point A to point B
@eVCANN
@eVCANN 9 ай бұрын
@@Muho_is_meyeah I noticed this in Stardew Valley, the camera moves a lot slower when walking diagonally and it feels painful so I just avoid walking diagonally even though I know it’s the same speed
@Allplussomeminus
@Allplussomeminus 4 ай бұрын
Bread and Butter for speedy movement in 007 Goldeneye (N64).
@Equal-zzz
@Equal-zzz 8 ай бұрын
In this type of game(with 8 direction movement) it is easier to just create a new constant that is approximately equal to sqrt2 and use it for diagonals. This reduces the need of constantly normalising direction vector, which implies square root every moving frame.
@nidbahn
@nidbahn 7 ай бұрын
divide the speed by sqrt2 and put it in both x and y of movement vector
@patrikugrin2592
@patrikugrin2592 9 ай бұрын
Every beginners first problem, it's quite fun to encounter these kind of problems
@codahighland
@codahighland 9 ай бұрын
If you have to use integer pixels, have moving diagonally by 2 pixels in each direction take three frames. This means you're moving sqrt(8)/3 pixels per frame, which is about 0.94, which is close enough to make the speed difference far less noticeable.
@Aerialyn
@Aerialyn 8 ай бұрын
Luna Game 3D has this error which helps immensely on speedruns
@waltercardcollector
@waltercardcollector 9 ай бұрын
I just want to say that I love your choice of background music (it's from Xenoblade which is one of my favorite games of all time)
@guimon78
@guimon78 5 ай бұрын
I appreciate the "Outside Colony 9 (Night)" as the music
@nikitapower947
@nikitapower947 8 ай бұрын
Several Zelda games even don’t mind that acceleration
@MinorLife10
@MinorLife10 9 ай бұрын
I swear to god, if JRPGs fix this "bug", that will make me hate them even more
@EyNickSee
@EyNickSee Ай бұрын
I'm learning gamedev/programming, and this helps understand the use of "normalize" so much more clearly now. Thank you
@softolive
@softolive 6 ай бұрын
If I were to make a game, I'd intentionally leave this in as a speedrunning strat
@mom0367
@mom0367 Жыл бұрын
Game dev is the only reason I'm genuinely interested in math class now.
@keroadh1455
@keroadh1455 9 ай бұрын
Teachers: “This is something you’ll need to know in the real world.” The one time I actually need to use it for:
@RotcodFox
@RotcodFox 7 ай бұрын
I personally wouldn't want to normalize the speed, because I'd be holding back speedrunners
@pickledokra2963
@pickledokra2963 7 ай бұрын
Ye but that's such a minute community in gaming
@esben181
@esben181 Жыл бұрын
I've never noticed that the diagonal movement in my prototype was like this. Thanks!
@Ridlay_
@Ridlay_ 7 ай бұрын
Dang, bro really just pulled out the Pythagorean theorem on me. Ok, I see you.
@soloshottie
@soloshottie 9 ай бұрын
fun fact: controller sticks have this kind of "normalizing" built in. since it can only rotate in a circle, it can only read X and Y axis inputs within that circle, meaning all edges of the stick are a 1 input, in some combination of X and Y
@nidbahn
@nidbahn 7 ай бұрын
this made me realize that sin²x+cos²x=1 also comes from the pythagorean theorem
@mmmmmmok5292
@mmmmmmok5292 5 ай бұрын
trig moment
@ErdrickHero
@ErdrickHero 4 ай бұрын
I hate that devs have started doing this without regard to the game in question. Moving faster at a diagonal can be a really fun movement technique.
@Phychologik
@Phychologik Жыл бұрын
This is always something that you could do, but it's not always something that you should do. For example, I know undertale doesn't do this, as it doesn't really have a reason to. If you were to do this to a game like undertale, you would be slowing down the movement for no good reason. Now if you had a game where your speed not being consistent would upset the balance of the game, like a game where you spend a lot of time running away from enemies, this would be a pretty good change.
@LeSpatiocorne
@LeSpatiocorne Ай бұрын
That remembers me the fact that some old games forgot it in some situations like in hitman bloodmoney where you're faster when dragging a body in diagonal.
@b.s.7693
@b.s.7693 7 ай бұрын
Bethesda didnt't know that up to Oblivion...
@Greywander87
@Greywander87 8 ай бұрын
This "bug" existed in a lot of older games. I remember in Perfect Dark on the N64, there were cheats you could unlock by beating levels in a certain time on a specific difficulty. By using diagonal strafing, you could speed your character up and beat the level faster. This is also an issue in any game with tile based movement, such as a lot of strategy games that use square grids. It's one of the reasons why a lot of people prefer hex grids, since there is no diagonal movement on a hex grid.
@ElFastasXD
@ElFastasXD 6 ай бұрын
Wow, 2D zelda games also reduces diagonal speed
@ChickenTandies
@ChickenTandies 9 ай бұрын
How anyone who goes through school and college not knowing this already baffles me. It’s vectors 101
@miles11we
@miles11we 6 ай бұрын
Well maybe I didn't graduate 4th grade
@someone7554
@someone7554 9 ай бұрын
We wouldn’t have this problem if the pixels were hexagons
@addictionsucks8848
@addictionsucks8848 6 ай бұрын
I actually kind of prefer the faster diagonal speed. I think having things that make big fans of the game faster or stronger without specifically adding in more equipment for them to grind to is underated. Being able to go 40% faster by figuring this out is so much more fun for me as a player than logging 20 hours for voots that do the same. And it being available from the start of the game just means that any returning player will be rewarded with tips and tricks from their intial play through. It will also help cut the time to retrace steps and travel times
@nidodson
@nidodson Ай бұрын
It still feels faster, because the screen scrolls in both directions, instead of just one.
@ismyname_jep1394
@ismyname_jep1394 2 жыл бұрын
Very informative, thank you!
@ImCrowned76
@ImCrowned76 6 ай бұрын
Of all the math I’ve learned until now, the pythagorean theorem seems to be the only one that keeps popping up as useful
@diitrii
@diitrii 8 ай бұрын
I love how you used two different algebra topics, even one from linear algebra, which is what I’m learning right now
@KieraQ0323
@KieraQ0323 6 ай бұрын
That's why I run diagonally in real life.
@TheActualDP
@TheActualDP 9 ай бұрын
i wrote a little multiplayer game as a kid where i noticed this, overcomplicated the math to fix it, and when me and my friends playtested it we decided it was more fun to keep fast the diagonal movement in
@gravestron9695
@gravestron9695 2 жыл бұрын
Very informative in terms of understanding why the problem is there. The video doesn't help much in terms of solving the problem though!
@firstname4337
@firstname4337 2 жыл бұрын
I know, right normalize it ! ok, show me the math,
@dreamy97836
@dreamy97836 2 жыл бұрын
when moving diagonally divide the speed by √2 to normalize it
@warguy6474
@warguy6474 10 ай бұрын
​@firstname4337 divide the vector by the magnitude, also known as length. Generalized by sqrt(x^2 + y^2) for [x ,y] in R^2.
@vulkanosaure
@vulkanosaure 9 ай бұрын
a general version of the solution where the angle of movement can be any angle (not only multiple of 45°) would be to use trigonometry ; vx = cos(angle) * velocity vy = sin(angle) * velocity then use vx and vy to increment your character's position. that's what you would need if your input system allow you to go in any direction (ex following your mouse)
@veggiet2009
@veggiet2009 9 ай бұрын
And suddenly that "automatic" diagonal movement is no longer automatic
@core3gamegd587
@core3gamegd587 9 ай бұрын
As a speedruner and programmer, I prefer making it even a little faster just because of how fun it is.
@pryntik9136
@pryntik9136 6 ай бұрын
Thanks ! Thanks to you I finally understood standardization 😁
@arctic8137
@arctic8137 Жыл бұрын
yeah i get that, BUT HOW DO I ACTUALLY ADD THIS!!!!
@ckorp666
@ckorp666 Жыл бұрын
you could just add (a) conditional check(s) for two perpendicular directions, and have them multiply ur effective speed by .6 to reduce it by 40%
@arctic8137
@arctic8137 Жыл бұрын
@@ckorp666 doesn’t help
@ckorp666
@ckorp666 Жыл бұрын
@@arctic8137 aight i wrote this real quick in GML, it should get the job done - player object create: spd = 6 diag_mult = 1 - player object step: xmove = (keyboard_check(ord("D")) - keyboard_check(ord("A"))) ymove = (keyboard_check(ord("S")) - keyboard_check(ord("W"))) xspd = spd * xmove yspd = spd * ymove diag_mult = 1 if !(xmove = 0) && !(ymove = 0) { diag_mult = .6 } x = x + (xspd * diag_mult) y = y + (yspd * diag_mult)
@BoardGameMaker4108
@BoardGameMaker4108 Жыл бұрын
This is probably a late reply but oh well. To "normalise" like it says in the video, you divide the X and Y by the distance moved. So, If you are moving orthogonally, or vertically, divide the X and Y by 1. If you are moving diagonally, divide the X and Y by 1.4. The key thing is to slow yourself down if you are going diagonal. To implement this for any direction, you can do something like: (set initial movement) x = 2 y = 3 (work out length of move) length = √(x * x + y * y) (normalise movement by dividing by length) x / length y / length (movement should now be exactly 1 unit in any direction) (multiply by speed or whatever for final value). The other comment replied with multiplication probably because that's quicker for a computer to do iirc.
@BoardGameMaker4108
@BoardGameMaker4108 Жыл бұрын
@@dephoro Sure, I was just explaining how to "normalise" a vector, so I kept the example as simple as possible. Normally my implementation doesn't use any branches at all. Normally it's just something like: - Get initial vector from input. - Normalise the vector (should just be a function called Normalise) Literally two function calls, you would be hard pressed to find a solution cleaner than that. The Normalise function is also quite a common operation that has been optimised to death(atleast with improvements to sqrt). You can modify it further if you need extra features, but I don't think it gets much simpler or faster than just input.Normalise(). If your engine doesn't have a native Normalise(), you can implement it yourself using pythagoras (it's a single line for the equation, and doesn't involve any branches). Normalise just takes a vector (an X and Y value) and outputs circular values for them, exactly as you describe(It outputs on a unit circle though). What is the difference between your solution and just normalise?
@c4c4cr0773
@c4c4cr0773 9 ай бұрын
This is also true for Doom and Doom 2 and many other early FPS. Moving in diagonal is the base for many speedruns.
@Tragedy-Tv
@Tragedy-Tv 8 ай бұрын
Alternative idea, keep the quirks and have fun speedrun tech to boost your game’s replayability
@ieatmicroplasticsforlunch
@ieatmicroplasticsforlunch 9 ай бұрын
Day 0 of not using the Pythagorean theorem as an adult in the real world
@RustyhairedAlp9575
@RustyhairedAlp9575 8 ай бұрын
This is why mathematicians hate chess
@AmyStrikesBack
@AmyStrikesBack 4 ай бұрын
Theres also the pokémon/RPG maker strat: forcing the player to Walk in tiles
@wyattr7982
@wyattr7982 6 ай бұрын
I feel like a lot of PC ports don’t correct for this, and im grateful for that
@Mioxitty
@Mioxitty 3 ай бұрын
Programming is the one place that made me grateful for school :)
@swolecole8899
@swolecole8899 5 ай бұрын
That’s why you move faster diagonally in undertale
@ThatRandomGamer_Main
@ThatRandomGamer_Main 9 ай бұрын
So that’s why you move faster in some games.
@ProCoder2040
@ProCoder2040 6 ай бұрын
I love the fast diagonal tho :(
@thegamingcow5072
@thegamingcow5072 27 күн бұрын
This is actually the first thing I learned for 2D movement in game design
@chainbladeallience
@chainbladeallience 8 ай бұрын
This didn't actually explain anything but it's hard to give programming tutorials through shorts, so I applaud you for trying anyway
@Krzztl
@Krzztl 2 ай бұрын
Oh so THAT’s how you use the pythagorean theorem
@Trashedaccount123
@Trashedaccount123 8 ай бұрын
I thought I was going crazy when I was moving faster diagonally in Mother 3
@waynegalen1538
@waynegalen1538 9 ай бұрын
This exact thing happens in the original Doom when you move forward and strafe at the same time
@CasualRandom50
@CasualRandom50 6 ай бұрын
Yesssss math in coding I love math in code because it has automatic functions for finding things and it makes you feel smart
@amiboacid7183
@amiboacid7183 8 ай бұрын
Elementary school knowledge
@JorisQC
@JorisQC 7 ай бұрын
One of the first things I learnt during my game development studies! 😊
@bradfjord
@bradfjord 8 ай бұрын
Understanding vectors and what normalizing does was like half of all my gamedev experience lmao
@traversal6881
@traversal6881 9 ай бұрын
There's also potential key conflicts depending how you code it - you can make it OG Pokemon style where two buttons pressed prioritises the one last pressed, limiting movement to the four cardinal directions. I'm love my nostalgia so I like to do this, lol.
@Trenty_Boi
@Trenty_Boi 9 ай бұрын
Remember kids: Even in vr games this diagonal concept works (I would know bec I've played vr games often that it works for but some you need to do it properly instead of just go diagonally)
@SiemJansen-x5f
@SiemJansen-x5f Ай бұрын
Thank you! I’m creating a game with a friend for school and this really helped!
@heyspookyboogie644
@heyspookyboogie644 8 ай бұрын
Imagine if this was the kind of example used when teaching the Pythagorean theorem in school.
@Xero-phantom89706
@Xero-phantom89706 8 ай бұрын
This breaks math
@wikedawsom
@wikedawsom 9 ай бұрын
For anyone looking to implement this, just remember with the pythag theorem, "c" should equal 1 unit of movement, so "a" and "b" need to be adjusted to maintain the same angle, while resulting in the correct "c" distance. Thankfully, you can accomplish this with some simple equations, and computers have calculators built-in, so you don't have to do the math yourself :)
@ClodsireBcuzYes
@ClodsireBcuzYes 4 ай бұрын
the one and only time that will come in handy
@totallynotyourmom5683
@totallynotyourmom5683 8 ай бұрын
Bro actually found a use for the Pythagorean theorem
@TristanDena
@TristanDena 7 ай бұрын
If it helps anyone, you should add to x: cos(angle off of the x axis you're moving at) * desired movement speed, and add to y: sin(angle off the y) * movespeed. This way even if you were moving in 360 degrees, you will always move at your desired movespeed in any given direction. Good luck
Can You Beat Hitman 3 Without Breaking ANY Laws?
22:37
windowledge
Рет қаралды 1,9 МЛН
Palx diei | geometry dash (Read the description for updates)
8:16
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19
Крутой фокус + секрет! #shorts
00:10
Роман Magic
Рет қаралды 18 МЛН
Please Help This Poor Boy 🙏
00:40
Alan Chikin Chow
Рет қаралды 11 МЛН
АЗАРТНИК 4 |СЕЗОН 3 Серия
30:50
Inter Production
Рет қаралды 1 МЛН
I Made the Same Game in 8 Engines
12:34
Emeral
Рет қаралды 4,1 МЛН
How speedrunners beat The Password Game in 24 seconds
8:39
EazySpeezy
Рет қаралды 1,2 МЛН
Creating SMART enemies from scratch! | Devlog
5:40
Challacade
Рет қаралды 330 М.
AI Learns to Play Tag (and breaks the game)
10:29
AI Warehouse
Рет қаралды 3,5 МЛН
How to ACTUALLY get into Gamedev
14:01
DaFluffyPotato
Рет қаралды 727 М.
This Game Is Free
19:05
DangerouslyFunny
Рет қаралды 3,2 МЛН
“How do you start Pixel Art?”…Here’s what I did!
12:42
Brandon James Greer
Рет қаралды 448 М.
I Spent 2,000 Hours Using Scratch
13:59
ggenije
Рет қаралды 604 М.
The Internet Played My Game (and it did not go well)
9:27
advancenine
Рет қаралды 252 М.
Do you choose Inside Out 2 or The Amazing World of Gumball? 🤔
00:19