kurtp2003 Member Posts: 48 From: minnesota, US Registered: 01-20-2006 |
I'm new here, so I don't know how many of you already know how to do this, but over the summer I did some work on making one object follow another at a rate that isn't affected by distance. This has many applications, but, in my case, the original reason was creating a source of gravity at the center of the screen for a space war (the very first video game) remake. Anyway, I after a lot of thinking I did come up with a process to do this. First we will need some generic variables to work with. x1(the x position of the source of gravity) x2(the x position of the object being affected by the gravity) okay that's all you need to start. Now let's use these to set the values of some new variables. xd=x2-x1 these will be the first two legs of an imaginary right triangle h=Sqr(Abs(xd)^2+Abs(yd)^2) now we have the last piece of the triangle; the hypotonuse. Next we find the sine and cosine. sin=xd/h now, you subtract those number from the speed of object#2. You can multipy or divide them by whatever you want to change the force of the gravity. Xspeed=Xspeed-sin
|
kurtp2003 Member Posts: 48 From: minnesota, US Registered: 01-20-2006 |
Okay, here is an example: Const upkey=200,rightkey=205,downkey=208,leftkey=203,space=57,bkey=48,f10=68 Type particle Type gravity g.gravity=New gravity While Not KeyDown(1) Cls If MouseDown(1) For p.particle=Each particle p\h#=Sqr(Abs(p\xd#)^2+Abs(p\yd#)^2) p\s#=p\xd#/p\h# p\xs#=p\xs#+p\s#
Text 10,10,"this works" For p.particle=Each particle Flip Wend End |
Realm Master Member Posts: 1971 From: USA Registered: 05-15-2005 |
veerrryyy interesting... cool! your a heck of a lot better in math than i am! (well, im good, but I just can't find any part of math to tie into my programming...) ------------------ Blessed are those who suffer for doing what is right. PM ME YOUR DESCRIPTION OF ME! ILL PUT IT HERE! |
firemaker103 Member Posts: 643 From: Registered: 07-13-2005 |
Relam, the magic functions: Sin and Cos ------------------ |
kurtp2003 Member Posts: 48 From: minnesota, US Registered: 01-20-2006 |
Thanks. Sorry I accidentally posted this on the wrong board, but I'm new here, so I'm probably going to make a few mistakes. Anyway, though this program looks nice (despite the simple interface) I'm really not a particularly good programmer- or kindof anyway. Because I'm completely sef taught I haven't learned to do a lot of basic things, but the stuff I do know how to do I can do as well as most people. |
buddboy Member Posts: 2220 From: New Albany, Indiana, U.S. Registered: 10-08-2004 |
wow... you just TOTALLY lost me in only 2 posts!! ;p;!!
------------------ |
kurtp2003 Member Posts: 48 From: minnesota, US Registered: 01-20-2006 |
quote:
|
firemaker103 Member Posts: 643 From: Registered: 07-13-2005 |
Yea, another blitz user! -- Anyway, besides from that teaching people, it can also make some good desgins ------------------ |