# Physics, Physics, Physics....

984 views

I thought I'd be stepping into the realm of physics with my next idea after Tower Defense because I wanna look at making one of those 'see how far you can throw this' kind of games and I figured hmm probably need to do the 'physics stuff'... I don't know it so well so its a great opportunity for me to learn it all..

A couple of examples would be 'Toss the Turtle' and 'Kitten Cannon', but I found out last night that I hadn't actually played Turtle since 2010... I don't know how I didn't know this, it felt so fresh in my mind! Anyway the relevant discovery is your 'player', your 'turtle' never moves beyond a certain X position...... It has a bounce (Gravity??) and then a rotation speed I guess just to give it the look and feel of motion.. I would think Animations would help here too...

So what this means is 'everything else' moves left instead of your player... Do I still need to mess around with physics? I'm still using Game Maker Studio for now.. I want to check out Unity and it seems their personal license is plenty fine but for now I'm in GML still... Whilst in GM, I was able to have a background 'tiled horizontally' "Scroll" indefinitely at a set speed.... Progress. Not the hardest thing to achieve...

I then made it 'slow down' on command, 'spacebar', if I command it again, it'll speed up again, so its a switch.. I feel like this would be the best method for the entire world to move and have things slow down.. If you were to hit an explosive or a spring or a 'boost' type object then you can switch off the 'slowdown' or reverse it so you're controlling the speed up.. whichever works best. And then after a second or two turn it to slow down again... Ultimately coming to a stop.

That was another thing too, getting it to cap the speed, wasn't too tough, I just gotta figure out what's too quick and then 'too slow' wouldn't matter because 0 is stop, it doesn't need to go in reverse........ Or does it hmmm I dunno if that would ever be a thing, The general idea is that it slows down and stops...

I made my 'player' bounce but maybe not in the best way possible, I used another switch 'fall' so if you are falling you are increasing you Y by bounceSpeed until a certain point, that certain point is the floor, when you hit the floor are NOT falling and you would decrease Y by bounceSpeed until you hit bounceHeight, then you would fall, But this just moves between the floor and a 'roof' ... So it would need to decrease everytime you 'bounce'.. I added in bounceHeight -= 200; which activates everytime you turn off falling... so ultimately you stop bouncing... That works too...

Still not using the built in physics and I've got the fundamental mechanic to the game (I think)... The only thing I need to figure out really is how to make your bounceSpeed, bounceHeight and backgroundSpeed all connect to each other... This is where I end up thinking I need physics... but I don't know. I believe in physics its no longer about x+= 5 but in fact you'd exert a force of '5' onto your object from a certain side which would make it react... gravity would just pull it down, forever, ??? So I'm not sure if I'm just as obsessed with Physics as David Tenant in Doctor Who or if I actually need to use it.....................

'States'

I don't fully understand how this would work but I think I would need to make a few 'states' in the game... and have it built like a giant switch statement?? I still wanna use these...somehow

But yeah, I was thinking, The start of your game is going to be State 1, 'IDLE'... This state has 'nothing' happening although a lot might be happening it just looks like nothing is happening.. until you click 'throw' 'launch' 'fire' etc (Unless you have a gauge and allow the player to adjust the power of the throw.... I dunno.. but until you 'fire' basically)

Then state 2 would be quite small, basic, short, whichever word... Because you'd need to 'start' the whole everything scrolls but your character/turtle/kitten doesn't just appear at position X, you go from your launcher to that position... and you need to move your launcher to the left a little bit (I was thinking destroy the launcher BUT if you do a really poor throw and land right next to your launcher,, even if you move a little bit.. It might still need to be visible so Destroy is NOT an option).. Once you've hit position X you clamp it, lock it, stop it, whatever its called and you'd want to switch to state 3.

State 3 is what I called Falling BUT maybe it'd be better to call it Flying... you might have some more momentum and still be flying through the clouds at this bit.... THEN falling... so State 4 would be Falling... switching between State 3 and State 4 if you hit boost items? For a certain time like 2 seconds?

State 5 is so close to State 1 but you'd want to calculate your score and and save your furthest distance and stuff like that... Then switch to State 1, and you're in a loop........ but does that even make sense and does that even work...... 😮 ....

States 1, 2 and 5 are fine, I can sort those out... Its just the Flying and Falling... switching between could be really easy, like change a few true and false and its switching... conditionally of course... Now would I even need to consider use of Physics for State 2 and State 3 ? I mean flying, you're going to move upwards 'lower' on the Y (I'm sorry I just gotta stop there.. This is really confusing to me because although you're going 'up' you actually going 'down' in terms of the value of Y -.- like 0 is the top, so to go up you need to decrease Y... legit Y is that a thing??? anyway.. )

This is not a top down game either so I'm not so sure how things would work in terms of setting the direction... Left is still angle 0 ... up is 90, down is 270, Would most likely need to set a range within 90 - 0 - 270 so you can't 'go backwards' either... I think that would be fairly 'easy' to maintain though.. This would also need to decrease along with the bounce/y position but perhaps not completely increase after a bounce...

I don't know... It's going to be super fun to figure out. And I'm sure some people can say "This is well easy dude! What the flip are you on about??" I'm hoping I can be as smart of those people some day and just know what everything does BUT y'all have to admit.. its a lot less fun 'now' when you can 'just' make stuff... Like to me, the fun part is the learning part. Once i'm a professional, I'd need to find fun through making crazy chaotic things happen ! I dunno.. Future stuff...

I just read the first half, and skimmed the second..  You may want to explore the physics option a little more..  Don't be intimidated.

It's a little bit of a learning curve, but it will really reduce the frustration you're having with the "movement" of the thrown object.

To throw it, you'll just add a force of some magnitude(number) to the object in some direction (x,y) vector.  A vector is essentially just a line that goes from 0,0 to whatever your specified x,y is(relative to whatever you're applying the force to, i.e. the thrown object is always the 0,0 part of the vector you're using for the force).  A vector and a point are represented the same, so it's confusing.

e.g.  if the object is @ 1,1 and you add a physics force with a vector of (1,0)  it will cause the object to move to the right at the speed of the (force magnitude) you applied.   A vector of (1,0.2) will give it a slight upward direction, but gravity will take over from there and bring it back down slowly, based on how much magnitude you give the force.

To handle the bounce and the slowdown, you can adjust the "bounciness" and "friction" of the object, and the objects it comes into contact with(ground,obstacles,etc.).  I'm assuming that GameMaker has physics materials as well.  These are materials that allow you to specify the bounciness or the friction that the object will have/create with other objects when they collide.  You should be able to assign these attributes (bounciness, and friction) in some way as they are key to using game physics, so if it's not physics materials that you apply to an object, then it will be somewhere else in there.

I would also rethink the moving of the whole world instead of the "thrown object".  It'll be hard to get physics working right the other way.  Just focus your "camera" or your "view" on the X(if x is left-right) position of the thrown object and whatever Y you like.  That way it always follows the thrown object and that's the only object you need to worry about moving or adding physics forces to.  Everything else should work the same, essentially.

Yeah, a simple state machine could be made with a variable to track the current "state" and a switch-case inside a main loop to "do something" when the state changes.  That's a pretty straight forward way to make it work.

Also, yeah, Unity is good to go for anybody who doesn't make more than $100,000 a year off of their games. It's fully capable and the very few Pro-only features they have are gonna be things you'll likely never need. #### Share this comment ##### Link to comment 21 minutes ago, Septopus said: A vector of (1,0.2) will give it a slight upward direction This is what I need to for flying and falling then! For sure! And the gravity pulls it in, it then would bounce 'off something' so invisible walls I imagine, In general would physics stuff eventually 'stop' ? Or would I need to tell them to 'stop' ? 21 minutes ago, Septopus said: assuming that GameMaker has physics materials Yeah, there is some 'physics' stuff in there, I just gotta learn it now then Something about being able to set a room to a physics world.. I dunno. I'm happy to learn though! It's fun 22 minutes ago, Septopus said: It'll be hard to get physics working right the other way. This is why I was thinking physics was not the way to go because of moving the world... Perhaps you would know of how to make an infinite world then? Because I'm all good with having the object followed by camera, I learnt that stuff in setting up for an RPG, But ultimately my 'object' runs out of 'room' It doesn't necessarily disappear, it just isn't followed anymore by my camera because basically its something like this: Room Size is the size of your world, (So i need to make this either majorly long horizontally? Would that break anything?), View is the camera, what the player sees, and Port is like my display window kind of thing. Now I know the 'meaning' of the 3 terms but I don't know the importance, Could I have like a million pixels horizontally without issues as long as its not in view yet? Or would my game wanna try loading everything in the room ? I imagine this would be something simple and I've just overlooked it -.- guna do a ton of googling before making anything proper for the game. 21 minutes ago, Septopus said:$100,000﻿﻿ a year

I'd be happy with that 😅

##### Link to comment

Getting a good understanding of physics is well worth the struggle and effort. You'll appreciate this new found knowledge and understanding when you find out how many great ways you can utilize it for your games!

##### Link to comment
7 minutes ago, CyberFlash said:

This is why I was thinking physics was not the way to go because of moving the world... Perhaps you would know of how to make an infinite world then? Because I'm all good with having the object followed by camera, I learnt that stuff in setting up for an RPG, But ultimately my 'object' runs out of 'room' It doesn't necessarily disappear, it just isn't followed anymore by my camera because basically its something like this:

2 ways I can think of.

1) make a really really long level by hand in a graphic editor/etc.... haha

2) Procedural level generation.   This is where you make smaller level segments that are just objects loaded by code to build a really really long level based on some randomness.  Which is way more fun.

7 minutes ago, CyberFlash said:

Room Size is the size of your world, (So i need to make this either majorly long horizontally? Would that break anything?), View is the camera, what the player sees, and Port is like my display window kind of thing. Now I know the 'meaning' of the 3 terms but I don't know the importance, Could I have like a million pixels horizontally without issues as long as its not in view yet? Or would my game wanna try loading everything in the room ?  I imagine this would be something simple and I've just overlooked it -.- guna do a ton of googling before making anything proper for the game.

Yeah, a LOT of that is very specific to Game Maker, so google is gonna be your friend there for sure.

7 minutes ago, CyberFlash said:

I'd be happy with that 😅

Yup!

##### Link to comment
3 hours ago, Septopus said:

Procedural level generation

This is what I was originally thinking of doing... but I guess I got it wrong because I thought that meant keeping my player at the same x and having everything else scroll right to left and destroy itself when its like -100 on the x (depends on size obviously) and have it randomly spawn on the right side in a sequence or randomly chosen sequence. My issue with doing this whilst letting the player move on x is I don't have a lot of width to play with unless I do suggestion 1 which is make a really long room. I'm going to consult the docs and try to understand how the world works again. I mainly messed around with a finite predetermined space when i made stuff so yeah. Its all good though. Thanks once again for the great advice!

3 hours ago, Rutin said:

Getting a good understanding of physics is well worth the struggle and effort.

The only thing now really is trying to decide if I should figure this out in Game Maker or just go get Unity again and learn & use that instead,

I even looked at export options and it seems fine, I just need Windows and I'm thinking maybe browser too so I don't have to people to install anything, I even think the splash screen forcing "Made with Unity" is cool these days too like saying "I'm using the pro stuff " lol

##### Link to comment

I'm going with Unity! Just a quick look/reminder of it, I don't have to define a horizontal limit in Unity. In Game Maker i've gotta set it as a fixed size of my room and I don't know how to do the unlimited running environment thing in there after a certain point in my room but in Unity I can just make a group with Camera, player and a wall that lags behind, anything beyond the wall is deleted and things spawn to the right moving left until after wall...  Boom that should sort it

##### Link to comment
1 hour ago, CyberFlash said:

suggestion 1 which is make a really long room.

I can't say for certain how it works in Game Maker, but I'm assuming the "room" concept is more or less just the size of the "canvas" on which you can place objects.  So you could do option #2 with a large "room" and lots of smaller sections of a large level..  if that makes sense.  Again, I might be confusing Game Maker terms, but that's how it sounds so consult the docs.

1 hour ago, CyberFlash said:

The only thing now really is trying to decide if I should figure this out in Game Maker or just go get Unity again and learn & use that instead,

I'm sure Game Maker will be fine for most anything 2D, and maybe better/easier for 2D than Unity is sometimes.  Just throwing that out there.  I had some frustrations trying to use Unity for 2D, but I also do things differently sometimes too, so, many possible explanations for that..   And, they've made a few advancements in the 2D area since then as well..  That all being said, if you want to go with Unity, just do it..  Actually nothing to lose, especially if you enjoy learning new stuff.

##### Link to comment

Yeahh, the issue with Game Maker is your 'room' is literally how large your world is so you've gotta set that, you'll have a 'view' like a Unity Camera, you can follow an object until it hits the limits of your room.. I imagine there's a way to extend the room size actively during the game or something like that but then also reducing it from the left so not to lag I dunno how that'd work. But by default as far as I'm aware, if you put width at 5000, 5001 isn't accessible in your view and you even get a popup from game maker stating somethings are outside your room 😓 but I think Unity could be fun anyways, I don't wanna be 2D forever so getting back into C# will help when I wanna do 3D... if all fails I'll run back to Game Maker and apologise 😂

##### Link to comment

Will you actually run into performance issues if your room is 10 or 20 or 30000 wide?  I like to push the limits and find that stuff out before I try anything..  That's just me though.  haha

The same goes for Unity, or any other programming related adventure.  Hard to tune anything if you don't know the actual limits.

##### Link to comment

That's a good point to make and definitely worth finding out, I do know of the 'containment limit' in Game Maker rather than performance like the fact that I've got to state the room size is enough for me to move to something without that limitation for a game where I'd want to make it 'endless' in some regard.

I'm not making a super rocket pro particle million asteroids game or anything but without spending a long time trying to build the game in Game Maker and testing out a bunch of different room sizes against my intended upgrade system I'm not going to know for sure what limits I'll have.

I don't know if 30000 wide would be too small.. I know at base level you won't throw the item that far but if you wanted to add upgrades you'd need to cap them and kill the fun and place a definite limit (in game maker), Unless there's a way to get around presetting room size. As far as I'm aware in Unity you don't have to define your world space? So you could go on forever. This is why i'm going to move to Unity and the fact that I just want to get back to using it again.

One day i'll test out performance with different room sizes but for me right now, the fact of putting a size at the beginning is a turn off because I'll never know without countless hours of testing how long to make the room realistically.

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

×