Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Builderboy

Pages: 1 ... 81 82 [83] 84 85 ... 375
1231
TI Z80 / Re: My explosive contest entry
« on: May 18, 2011, 11:36:37 pm »
Lol guys don't worry, pulleys are not working :P I tried to get them to work but they build up a kind of resonance between the two systems and fail catastrophically.

For the gun aiming, I am still working on it, but you use the arrow keys.  How it works is you press 2nd to bring up the gun, aim with the arrow keys, and upon releasing the 2nd key you fire.  This can be a bit weird tho... but i don't want the gun to be out all the time so im not sure.  Maybe press alpha to go into shoot mode, and press 2nd to shoot

1232
TI Z80 / Re: My explosive contest entry
« on: May 18, 2011, 10:12:42 pm »
Hmmmmm definitely not blocks and tackles, but pulleys might be a possibility, I will have to run some tests

EDIT: Early tests show probably not D: because the lengths of the rope are now varying at random and unspecific lengths, I am forced to do 2 square roots, which isn't good speed wise.  What is more is that the physics is really unstable and It can break itself pretty easily D:

1233
TI Z80 / Re: My explosive contest entry
« on: May 18, 2011, 07:12:45 pm »
I know physics really well because I have taken 3 advanced physics classes, as well as many advanced mathematics classes, and because I have taken calculus based physics ^-^

1234
Axe / Re: Physics Lessons
« on: May 18, 2011, 07:10:51 pm »
Single Segmented Rope Physics

   The situation is always the same, you are making your physics puzzle game that may or may not be a platformer, you want to add in a new game element, but you can't think of anything to add!  Maybe you want to add in some sort of rope element, but how in the world could we do this fast and efficiently?  Well this tutorial is going to teach you how to make a Single Segmented Force Based Rope Physics engine :D  That might sound complicated but lets break it down:

1) Single Segmented

    What single segmented means is that your rope will consist of only a single segment.  What this means is that we will only simulate the start and end of the rope, none of the stuff in the middle where the rope bends or whatnot.  Since one end of the rope is going to be fixed to a wall, in this tutorial we will only be simulating the object that is attached to the end of the rope.  When you go to display the rope however, you don't have to simply draw a line between the anchor and the object, you can get creative and do fancy things, but that is outside this tutorial.

2) Force Based

    There are many types of physics engines, and when combining them to create complicated effects, weird things can start to happen.  If one part of the physics engine devoted to rope physics moves an object without checking the other parts, it might accidentally move it into a wall or another object!  For this reason, the only thing this physics engine will do is impart forces onto the object, it will not move them.  We are also going to be assuming this rope is infinitely strong, and we will be ignoring the mass of the object.  By using only a force based engine, this gives us the highest possibility that this code will be able to be implemented into your existing engine.

3) The Conecpt

    So what happens to an object that is attached to a string?  What forces are exerted on it?  Before we can answer those questions, we need to decide how to define the string itself.  It needs an anchor point, and a length, so we will use three variables X,Y and L, to represent these.  We also need to use certain variables from our object, such as its position (I,J) and velocity (A,B).
 
Whenever the distance D from the object to the anchor is less than the length, we know that the rope is not going to be taught, and therefor cannot be imparting any force on the ball.  We could calculate the distance using the pythagorean theorem:

Code: [Select]
Sqrt((X-I)^2+(Y-J)^2)=D
But that uses a square root, and those are slow and sad.  Instead, we are going to square both sizes of the equation, since squaring is fast and happy!

Code: [Select]
(X-I)^2+(Y-J)^2=D^2
So now when we compare D to L, we will actually be comparing D^2 to L^2.  The size difference doesnt matter, since are only seeing if D is greater than L.  If you are using a x256 precision engine (which you should be :P) you can use this piece of code to find the distance in pixels (not x256!)

Code: [Select]
abs(X-I)->r1*^r1+(abs(Y-J)->r1*^r1)->D
So now we can tell if the object is pulling the string taught, or if it is letting it slack.  Obviously if it is slack (D<L) then we do not need to apply any force to the ball at all.  It is what happen when the string it taught (D>=L) that we start needing to apply a force. 

When a ball is moving out of the allowable ring of movement that the string allows, the first thing we need to do is eliminate the velocity that is taking it outside the ring.  This does not mean setting the velocity to 0.  This does also not mean we negate the velocity.  Imagine this:  The ball is falling straight down with the string above it.  When the string pulls taught, the ball will be yanked back up again and lose almost all velocity very quickly.  But if you drop it from an angle, off to the side, it will lose a little speed, but most of it will be transfered into a pendulum motion.  In a sense, all of the velocity that is directed out of the ring is being removed, and anything that is in line with the ring (tangential, its the motions it moves in when it swings) is kept.  Now this is a bit tricky to do, so bear with me here:

I-X//L->N
J-Y//L->O

This finds the Normal Vector of the string.  The math behind it isn't that important except that you know that it points in the same direction as the string, from base to object.  This will be important in determining how much velocity to remove, and from what direction to remove it from.  The string is the only thing that can take velocity from the object, and as such, it can only affect the object in the same direction the string is pointing.  The significance of this is that any change in the velocity of the object will be a multiple of this Normal Vector!  All that is left is to find this coefficient!

That coefficient just so happens to be the dot product of the objects velocity and the ropes normal vector.  A**N + (B**O)*-1->K
Spoiler For Spoiler:
Yeah, this isn't the 100% right dot product.  Technically speaking we would have to multiply two Normal Vectors, and AB is not normal.  But since we are going to be multiplying by AB anyways, we just combine the steps by not dividing and multiplying by AB :P I put this in a spoiler just because its pretty involved vector physics and not needed for the tutorial.  Similarly, multiplying by -1 isn't something that is done in a dot product, but is done later twice so i moved it back here so we only had to do it once :)

Now we need to do a quick test.  On the off chance that the ball is outside L, but actually moving *towards* the rope, K will be positive, and you don't want to affect the ball in this case.

Code: [Select]
If K<<0
Now all that is left to do is to add the velocity to the object!

Code: [Select]
K**N+A->A
K**O+B->B

Note that this will remove all velocity that is taking the ball outside the ring of string; stop it dead.  Sometimes this is undesired, so you can make it pull a little bit more and give the string a little "bounce"

Code: [Select]
K**N*3//2+A->A
K**O*3//2+B->B

And thats it!  You are done!  This is what the final result should look like when you piece all this together:
(Note that L^2 has been precomputed and put into M)

Code: [Select]
If abs(X-I)->r1*^r1+(abs(Y-J)->r1*^r1)<M
I-X//L->N
J-Y//L->O
A**N+(B**O)*-1->K
If K<<0
K**N*3//2+A->A
K**O*3//2+B->B
End
End

And this is what it should look like when implemented into a simple program!



1235
TI Z80 / Re: [2011 Axe Entry] Uncharted TI
« on: May 18, 2011, 06:21:46 pm »
set the X velocity for the hit box to the old one and do -(Xvelocity//2) -> Xvelocity of the other one.
That does't conserve energy or momentum :P The physically accurate thing to do is swap their velocities (assuming they have the same mass).

That looks really awesome :D I did notice a few quirks though, it seemed one time you jumped into a box and it moved towards you?  Still a few bugs i guess ^^ But I can't wait for this to come out :D There are so many awesome games being made for this contest!  The competition is really fierce ^^


Methinks I will post a single segmented rope tutorial :D

1236
TI Z80 / Re: My explosive contest entry
« on: May 18, 2011, 06:13:11 pm »
Yeah its only one segment, and I plan to keep it that way for memory and speed reasons.  Unlike your physics engine Ashbad, I am actually calculating each collision between each object, and so I have N^2 collisions (well, not quite since its a bit more complicated and when objects are stationary they go into "sleeping mode" where they no longer look for collisions) but it's still a large speed hog, and so I decided to just stick to single segmented rope.  I may, however, upgrade the graphics of the rope when it is not taught such that it looks like it is slack, but I'll have to run some more tests.

The physics engine is based off of my experience with Zedd, and so its completely receptive to force based changes.  Meaning I can have the physics engine running by itself and solving for all the movements of all the objects, and then I can randomly attach a rope to an object without telling the physics engine, and as long as I keep updating the rope on my end, the physics engine does the same ^^

1237
Axe / Re: Axe Q&A
« on: May 18, 2011, 01:09:24 pm »
Is it a scrolling tilemap?

1238
TI Z80 / Re: xy
« on: May 18, 2011, 01:48:20 am »
Hmmm i watched it again and didn't see where there was a shockwave o.O It always looks like you're just moving it around with momentum and stuff?  And I haven't taken a look at the code actually, I might when I have more time tho ^^

1239
TI Z80 / Re: xy
« on: May 18, 2011, 01:44:46 am »
I watched the whole screenshot but I didn't think i saw it? o.O

1240
TI Z80 / Re: xy
« on: May 18, 2011, 01:41:55 am »
I definitely think all these graphical effects are really awesome ^^ Although I'm still a bit confused as to how this is going to turn into a game?  Could you elaborate a bit more?

1241
TI Z80 / Re: My explosive contest entry
« on: May 17, 2011, 11:23:17 pm »
One thing, though: Shouldn't you be dying, exploding into pieces when blowing up stuff so close? ???

Nope, you are invulnerable to explosions :) Probably has something to do with your ability to pull large weapons 4 times your size out of thin air. :P

1242
TI Z80 / Re: My explosive contest entry
« on: May 17, 2011, 10:43:13 pm »
yeah, the box doesn't have the most traction so staying on a swinging platform is pretty hard, the explosives are the best part tho :D

1243
TI Z80 / Re: My explosive contest entry
« on: May 17, 2011, 10:36:12 pm »
I don't know what I'm going to call it yet Darl, but I'm sure it won't be too hard ^^

1244
TI Z80 / Re: My explosive contest entry
« on: May 17, 2011, 10:30:53 pm »
Nooooo don't give up :(

1245
Don't get overwhelmed though, a lot of those tutorials can be pretty specific and hard to understand without a basic understanding of axe

Pages: 1 ... 81 82 [83] 84 85 ... 375