Grafton Globe Newspaper
Winter 2020 Edition
hi. i’m jack. i made jack’s snacks earlier, then i lost motivation. ended up not doing anything for a whole year. so, yeah, that’s gone now. but now we have this!! oh man. you’re gonna love this. unless you got a problem with lowercase letters and really informal writing (this will be very informal! ya don’t need big fancy words to be interesting). oh yeah also this is about vidya games. even if you’re just like “what da heck is a video games” i think you can still enjoy this. another great thing about this is that there’s a whole lot to talk about, so there’s nothing really able to halt this unless i lose motivation again! i hope that doesn’t happen. for this series, i will be using gms2, but you can really use anything. i think unity is great (also free. if you are starting out, probably use that). everything here will never be engine specific so don’t worry about it. also, i have a real video game (http://joecularchaos.com)!! i have been working on it for a while, and i will be working on it for forever! it will be released, for money, eventually. oh yeah, i’m supposed to be writing about interesting things. i will do that now today i will talk about… MOVING! i’m gonna start the series off with something simple (relatively). movement. games tend to have that. usually when you play a video game, you can press buttons to move. seems pretty simple, but there are a couple things that are overlooked all the time. first thing, diagonal movement. so many new developers get this wrong!! usually, it’s not that big of an issue, but if moving is important in your game (which it usually is), it’s gonna be a problem. so, what am i talking about, anyway? well, a lot of people think of programming movement like this: if you press right, move the character right 1 unit if you press left, move the character left 1 unit if you press up, move the character up 1 unit if you press down, move the character down 1 unit seems like there’s nothing wrong with this, but there’s a big issue. if you hit right and up at the same time, it goes right one unit and up one unit. again, seems like everything is fine. but, have a look at this: see what i’m getting at? diagonal movement is faster than cardinal movement (up, down, left, right). that’s a big no no. math paragraph! moving diagonally multiplies the regular speed by √2 because right triangles are really funny. if the two sides of a triangle that make a right angle are 1 unit in length, the hypotenuse has a length of √2 (1^2+1^2=c^2, 1+1=c^2, c^2=2, c=√2). so, moving diagonally moves you more distance from your starting point than moving cardinally. so, how do we fix this? well, there’s a bunch of ways. the most efficient option really depends on the engine you’re using. i don’t really want to get into it since it involves circles and triangles and a lot of math. depending on the way you do it. alright! there’s our new movement, lookin’ real nice there. but there’s one issue... there’s no collision! you just go right through the wall. let’s go over some basic collision, and work our way up from there (there is a lot to be done). first, we’ll check if the player will collide with a wall if he moves. if there’s a collision, it doesn’t move. simple, right? well, it works. but there’s a problem... if you move diagonally into a wall, you completely stop. that’s probably not good. the way to fix this is to check for x and y collision separately. that way, if you’re moving up and right into a wall to the right, you will stop moving right but continue to move up. here’s what it looks like when this is fixed. but there’s another issue! kind of. it’s not necessary, but it makes things look a lot nicer. if you look closely, you should be able to see that the player isn’t always touching the wall, sometimes a couple pixels off. the way to fix this is to “snap” the player to the wall if it gets close enough. basically, if a collision is detected in a direction, a loop moves the player one pixel each repetition until it’s touching the wall. that way, whenever there’s a collision, the player is always right up against that wall. here’s that in action. another small thing to add is flipping the sprite horizontally depending on where it’s going. and there you go! basic movement in a game. yeah, not exactly simple. and that’s only step one!
alright, well, that’s the first entry in whatever this is. go vote for the next topic here: https://goo.gl/forms/k2969JISSuD4FhcD3
0 Comments
Leave a Reply. |
Grafton Globe NewspaperStudent created articles in a student run digital newspaper. CategoriesArchives
February 2020
CategoriesHumans of Grafton High |