Game Development Community

Simple Physics?

by George Fairs · in Torque Game Builder · 11/16/2009 (4:13 pm) · 25 replies

Hello everyone!

I want to start making a VERY simple physics based game that involves balls hitting a bat continuously. How do I make simple physics such as the gravity and the deflection?

This is just a project to help improve my skills, but I am not quite sure where to start.

Thanks.
Page «Previous 1 2
#1
11/16/2009 (4:29 pm)
Going through Behavior tutorials would be a good start.Then Collisions and World limits tutorials should give you a pretty clear idea of how things work.(it's all in the official documentation which comes with TGB in case you missed it)
Good luck
#2
11/17/2009 (4:32 am)
Thanks. I have done a few of the tutorials but they don't really help with what I need.

Let's say as an example, a ball is the only thing on the scene, and when I run the scene I want it to drop? How would I do this?

Thanks...
#3
11/17/2009 (7:04 am)
When you open TGB editor, you first import some graphic to work with. then you put that graphic (as an object) on the stage. then you select that object and in the properties panel, you can activate and modify physics of an object. Also you'll have to activate collisions for that object.

For start, its best to set gravitic forces to apply to the object, that way, you'll see the effects of physics immediately.
#4
11/17/2009 (3:11 pm)
Ok, I tried that out. I just placed a square tile and gave it the physics property gravitic, but this was to no avail.

Any ideas now?
#5
11/17/2009 (5:19 pm)
Anyone? It doesn't work, the tile just stays where it is (it's not on a tilemap :P)

Thanks...
#6
11/17/2009 (6:10 pm)
Well, it depends how you enabled that physics. Maybe you are doing something wrong, i cant tell looking from out here :)

Try to re-check what you have selected as properties of that object. And that it is not set to "unmovable".

You can manually set some force to the object in game.cs file inside of startGame() function. Set a name to that square and write:
squareName.setImpulseForce(100, 0, true);
echo("code executed, force has being applied!");

This should move that object temporarely by speed of 100 to the "left" and it will apply gravitic force.
Echo should print a message in the console (that you can open in game with ~) to see weather or not your code has actually being executed or not. (remember to save all files before testing)
#7
11/17/2009 (6:27 pm)
Ok, I am about to try this, but where in the game.cs should I place this, and should I apply squareName to my object?

Thanks
#8
11/17/2009 (6:31 pm)
I know where to put it, sorry :P

I gave my object squareName class and name, but this error occured:

"Error: cannot change namespace parent linkage of squareName from t2dStaticSprite to squareName".

???
Thanks!
#9
11/17/2009 (6:36 pm)
Nevermind, I sorted it :D it was going so fast with no world bounds that it went off screen. It is only going from one edge of the screen to another though, no gravity or anything else?
Help please :S

Thanks.
#10
11/18/2009 (3:48 am)
Anyone? Please?

The gravuty still isn't working?

Any ideas?

Thanks
#11
11/18/2009 (6:05 am)
Try reducing the forces, experiment a little. Also, set the world limit to that object (in TGB editor). Or set other objects that it can hit (you'll have to set collision layers right)
#12
11/18/2009 (1:44 pm)
"Gravitic" does not turn on a gravity force. You need to set a "Constant force" in the y direction (if things should fall downwards). This force pulls them downwards, and "heavier" (= bigger) objects fall slower than "lighter" (= smaller) ones (according to F = m*a), UNLESS you turn on the "Gravitic" checkbox. In this case the force simulates gravity (which depends on mass), and all objects fall with the same speed.
#13
11/18/2009 (2:24 pm)
So how do I make physics work without applying a force? I just want my object to fall and stop.

Help?

Sorry for being an idiot, but that's what I am. I am a colossal newb with these things, so please bare with me...

Thanks :S
#14
11/18/2009 (3:50 pm)
Nothing moves without a force, so this is ok. Dynamics is about force and movement. Turn on the constant force y, and things will be accelerated downwards.
To make your falling object stop, add another object simulating the ground. Go to Collisions and turn collisions on for both objects (so they take note of each other), and set CLAMP as "Collision Response" for your falling object; it will then stick to the ground (as if glue was applied to it - not much of a simulation). More sophisticated is "Collision Response" = RIGID, which simulates a rigid body. You need to turn on "Receive Physics" for the falling object, so that physics will applied to it. It will then bounce upwards like a basketball, depending on the valie of "Restitution". Set to !, it simulates a 100% elastic bounce; with lower values the object looses energy while bouncing, which is more realistic.

Of course setting the world limits of the falling object works as well.

btw I am absolute newb myself, but I am presently experimenting myself with these topics... TGB lacks a real manual, there is just a bag of tutorials, which often does not help enough...

#15
11/18/2009 (4:06 pm)
So is there any real physics within TGB? I have seen things on the internet presenting them but I am not sure.

I don't want to have to apply a force of any kind. I just want the object to fall, and if it hits something else bounce in the right direction based on real life like physics.

Sorry to be asking the same thing over and over, but I am not sure what you have said is what I'm looking for :S

Thanks (and sorry again).
#16
11/19/2009 (2:16 am)
If you do not apply a force, your object does not fall at all. So you do not want your object to fall but to move downwards. So it needs a velocity, which again you apply in the Physics section. Then you set the world limits to the visible area and set collision response to BOUNCE, The object will now move downwards with a constant velocity (this is no falling motion...) and bounce back, with the same constant velocity. This will have a very unnatural look, more like looking from the top instead from the side.

TGB has some basic physics with some clever features. However ist does not have a "global" gravity, and there can only be one force applied to each object. I think Box2D will improve this.
#17
11/19/2009 (4:02 am)
Hmm... Yeah, I am looking for a very natural physics motion, but it sounds as though I cannot achieve that.

Thanks anyway everyone.
#18
11/19/2009 (8:32 am)
I wasn't working with gravitic physics for a long time, but as far as i remember, when i was testing the gravitic TGB physics, i just putted some objects on the screen, and they fell down like a rock.

Objects was bouncing, rotating... TGB have pretty much real physics engine implemented.
#19
11/19/2009 (1:31 pm)
Mine isn't doing that at all? I applied the gravitic check box but it just stays there. I really beed help, seeing as you got yours to do that.

Thanks :D
#20
11/19/2009 (7:00 pm)
Here is one of my first test-projects. There is no gravitic physics there, but you can see how physics in TGB can work. (it was made for TGB v172)

www.nutrilans.com/files/Loptice.rar

You probably wont understand a lot of code (comments, and function names) since i wrote it all in Serbian ;)
Page «Previous 1 2