TNT Basic Forums > Programming Q&A
Gravity and Collisions
< Last Thread     Next Thread >
Thread        Post A Reply

01-16-2003 05:53

Posted by:

Click Here to Email t-maaz   Find more posts by t-maaz

Hey all - I am new to the TNT Basic software, and I have a question that I can't find posts or FAQ/help answers for. This is a two-parter:

1) Direction of gravity: I noticed in the samples that are shown, the gravity direction is (obviously) "down"... from top to bottom of the screen. Is it possible to have an overhead view gme, or a 3/4 view game (where the ground is slightly sloped upward from the bottom, giving a "field of view" ahead) and have the gravity be to the correct plane? I am a bit stumped as to how to accomplish this.

2) Collisions: The effect I am looking for is identical to when you play pool, and you "break"... one object hits another object, and both the objects react to the collision by a bounce/movement, possibly hitting other objects and inducing the same action/reaction, etc. I found information for how to "detect" a collision... do I need to manually add in the physics calculations to take this to the level I am looking for? Or does TNT already have some physics such as this coded in?

You answers/input are greatly appreciated!!


01-16-2003 07:00

Posted by:

Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

ho ho...

1)The gravity itself is not pre coded as you may think: you need to code it yourself.
It' s not too difficult:

"x","y" are the x,y coordinates of an object

"xvel", "yvel" are the x and y components of the speed: every frame you put "x= x+xvel" and "y= y+ yvel"

the gravity : normally there is only x gravity (xgrav):
you put (every frame) "xvel= xvel + xgrav".

If you want gravity to go also a little left or right define "ygrav", then every frame put
"yvel=yvel+ ygrav"

the system is


xvel= xvel + xgrav
yvel=yvel+ ygrav
x= x+xvel
y= y+ yvel
sprite 0,x,y,0
draw frame


you should then deal with the rest, such as jumpin and touching the ground.

2) Ho ho... This is sure not precoded and is surely not a trivial task... good luck... ho ho...

01-17-2003 19:32

Posted by:

Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

The latter one (the collision one) is extremely difficult to do completely accurately. Here's how to do it, however, if you are willing to have imperfect physics. You just swap velocities. This is accurate in some cases, but assumes the following things:

1. The objects are of equal mass.
2. The objects are circular and hit straight on.

Two objects hit one another called ob1 and ob2

float ob1xvel,ob2xvel,ob1yvel,ob2yvel,temp

'this is what to do when they hit

temp = ob1xvel
ob1xvel = ob2xvel
ob2xvel = temp

temp = ob1yvel
ob1yvel = ob2yvel
ob2yvel = temp

For something more accurate you can do the following things. After all this has been done, multiply each objects x and y velocities by a number between 0 and 1. This will simulate the energy lost due to friction, sound, and whatever.

For a thread about the horribly complex issues of collision go here:;threadid=1773&highlight=collision

These are smart people, check out the links they provide.

01-20-2003 19:57

Posted by:


Click Here to Email mark_667   Find more posts by mark_667

xvel & yvel

some questions about Matteo's very helpful coding example above, please. Most errors I have are identical & the above code offers a way to fix most of them (I want to move sprites down the screen automatically). After reading all the comments I tried a similar syntax, but in my case there is no need for gravity. Below is one example, although the xvel and yvel have clearly been declared, the first y on the second to last line is highlighted as being a syntax error, and +Yvel is highlighted as being an illegal expression?


float Yvel=6, Xvel=6
'Move opponant down the screen toward player
Sprite off 0
Sprite 7,2,0
sprite 7,11,9 'Opponant
draw frame

Any advice apreciated,

01-20-2003 21:01

Posted by:

Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

the code

I dont know if these are the problems, any way this is how i' d write the stuff:

ProgressBar(): I' d avoid procedures if I were you: Untill your code exceeds 1000 lines they are not particularly usefull and you must know how to use them.

float Yvel=6, Xvel=6 : I think it' s better to do:

float Yvel=6
float Xvel=6
Since "," does not work.

Sprite 7,2,0: you must put 4 arguements in sprite;
sprite 7,11,9: same thing
y=y+Yvel: did you declare y?
Anyway, if you want to change the sprites position, you must put "y" as one of the coordinates when calling "sprite".

Please explain better what you want to do, maybe I could help.


01-22-2003 11:01

Posted by:


Click Here to Email mark_667   Find more posts by mark_667


In response to Matteo's response, I want the sprites in the example to automatically move down the screen in the general direction of the player, unaffected by user inputs until they are killed. The ProgressBar() is OK, I included that accidewntally.
Hope this clarifies a few things,

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.