Game Development Community

Screenshots of my project (so far)

by Jacob Vann · in Torque Game Builder · 08/21/2005 (3:52 pm) · 15 replies

Hey guys -

I've been a T2D user for a whole week now. It is great, I only wish I had more free time to work with it! All I really have so far is loading a tilemap, a camera mounted to the character and very rudamentary animation, movement, and collisions. I'm holding off any real serious programming until the new version comes out (the stock collision models sound awesome). In lieu of programming I've been working on my tilesets.

Please look at some screenshots and let me know what you think! You can see some of the artifacts of filtering in the 3rd screenshot. And I'm not too happy with that rock tileset, I'll be changing it soon.

www.jacobvann.com/T2D/torquess1.png
www.jacobvann.com/T2D/torquess2.png
www.jacobvann.com/T2D/torquess4.png

-Jacob

#1
08/22/2005 (4:19 am)
Looks good, Jacob. Have you been able to get the collisions to work properly with the sloped tiles? I'm doing something similar right now and for some reason the character keeps getting stuck on slopes. I'd be curious to hear how you implemented yours (via onCollision, through physics, etc).
#2
08/22/2005 (7:56 am)
Unfortunately none of the collisions are working quite right. Right now I'm just using an onCollision method. I haven't spent much time on it yet. If I get a good working collision setup, I'll post some code here.

-Jacob
#3
08/22/2005 (10:52 am)
Cool...
#4
08/22/2005 (10:57 am)
Love the art
#5
08/22/2005 (10:21 pm)
I worked a crapload on the rocky-cave tileset (to replace the one in the 3rd screenshot). I really like the result. As you can tell (or perhaps not), I've been playing Metroid Zero Mission a bit lately. :)

www.jacobvann.com/T2D/torquess4.png
(shrunk down to 640x480)

Again, let me know what you think!
#6
08/23/2005 (12:17 pm)
I liked the first set of rocks, but the new one is much smoother and looks sharper. By the way, what kind of problems are you having with collisions?

-Peter
#7
08/23/2005 (12:46 pm)
Quote - "smoother and looks sharper"
Haha that's kinda funny. I know what you mean but it's still funny.

I love the art, especially the character. Very detailed, very nice. :)
#8
08/23/2005 (2:49 pm)
Looking good.

you should do some futurist ones :D
#9
08/23/2005 (4:58 pm)
Thanks for the compliments, guys!

@Peter: My biggest problem is the character won't walk while on the ground. I read that since I'm applying a constant force (gravity), then the character will get collisions when walking sideways on a surface. I think I can fix this by basically removing gravity when the character is on the ground. I haven't spent enough time messing with the code, since I've been wrapped up in making tiles!

Anyone have a tutorial for simple side-scrolling collisions and physics?

@Darren: Since the game takes place in essentially a ruined civilization, there won't be too many "futuristic" looking levels. However, there will be plenty of technology, and lots of blinky lights, etc. :)
#10
08/25/2005 (8:15 am)
Here's the little known secret about collisions. You can find out which direction they're coming from. The onCollision function has the normal. The normal is a vector that you can use to find out if the collision is horizontal or vertical. Use echo to test it and figure out exactly how it works. So basicly if you have a verticle collision then change you're Y velocity to 0 and you'll keep moving horizontally. Same is true for horizontal collisions. Like I said it takes a little exparamentation to figure out what values of the normal are what, but once you got it everything's great.

-Peter
#11
08/25/2005 (10:23 am)
To expand on what Peter said, what you really want to do is subtract off the part of the velocity that is into the surface in question. If you are only colliding against horizontal or vertical surfaces, Peter's way will work just fine (and be simpler and faster). If you want to be able to walk down or up ramps of various angles, this is the way to handle it.
// In this example, %srcObj is assumed to be the character and %dstObj the surface.
function fxSceneObject2D::onCollision(%srcObj, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts)
{
   // New Velocity = Velocity + (-dot(Velocity, normal) * normal)

   // Grab the velocity
   %vel = %srcObj.getLinearVelocity();
   %velx = getWord(%vel, 0);
   %vely = getWord(%vel, 1);

   // Grab components of the normal
   %normx = getWord(%normal, 0);
   %normy = getWord(%normal, 1);

   // Compute dot product.
   // I don't think Torque Script has a dot product function. It should.
   %dot = (%velx * %normx) + (%vely * %normy);

   // Calculate the new velocity
   %vel = vectorAdd2D(%vel, vectorScale2D(%normal, -%dot));

   // Set the velocity
   %srcObj.setLinearVelocityY(getWord(%vel, 1));
}

To see this in action, throw this at the end of 'setupT2DScene' in client.cs:
$x = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   $x.setPosition("0 0");
   $x.setImageMap(ggLogoImageMap);
   $x.setConstantForce("0 100", true);
   $x.setSize("5 5");
   $x.setCollisionActive(true, false);
   $x.setCollisionCallback(true);
   $x.setCollisionPolyPrimitive(8);
   
   %y = new fxStaticSprite2D() { scenegraph = t2dSceneGraph; };
   %y.setImageMap(tileMapImageMap);
   %y.setPosition("0 10");
   // Change this to experiment with different angles of surfaces
   %y.setRotation(45);
   %y.setSize("50 2");
   %y.setCollisionActive(false, true);
And add this after the 'setupT2DScene' function:
function moveLeft(%val)
{
   if (%val)
      $x.setLinearVelocityX(-10);
   else
      $x.setLinearVelocityX(0);
}

function moveRight(%val)
{
   if (%val)
      $x.setLinearVelocityX(10);
   else
      $x.setLinearVelocityX(0);
}

new ActionMap(moveMap);
moveMap.bind(keyboard, left, "moveLeft");
moveMap.bind(keyboard, right, "moveRight");
moveMap.push();

Edit: By the way, I really like the art.
#12
08/25/2005 (2:29 pm)
You guys are amazing! I will try it out tonight or tomorrow.

Thanks Peter and Adam.
#13
08/26/2005 (7:43 pm)
Adam, I was able to plug in your collision callback, and it runs. The code is very well written and will put me on the right path ... However, when using it in my game I encountered a couple of odd glitches. I will work through them myself, but I thought I would share them with you if you have obvious solutions.

It definitely makes the character walk along surfaces much better. He even goes up the 45 degree ramps. However, there is now an odd problem at the seams of tiles. on horizontal surfaces, he gets stuck. I've found that it is colliding with the corner of the tile sometimes and gets a normal of (sqrt(2)/2, sqr(2)/2), and is being pushed back.

And when two angled tiles are on top of each other (forming a long 45 degree angle ramp out of two tiles), the character will walk up the first tile correctly, but then will walk horizontally through the second tile as if it is not there. Probably a similar problem as the one above, with the normal being calculated wrong on the seams.

Also, the character "sinks" quite slowly into the angle tiles while standing on them. I can't explain this one.
#14
08/26/2005 (8:01 pm)
Nice art!
#15
08/27/2005 (12:39 pm)
All right, I looked into this a little bit. It's going to be quite the pain, I think. My main priority right now is the scene editor I'm building, but I will spend a little bit of time working on this. I love platformers and yours is certainly going to look good, so I hope I've given you enough of a start to work with.

One quick change to the code I wrote above.
%srcObj.setLinearVelocityY(getWord(%vel, 1));
should be
if (isRunSurface(%normal))
   %srcObj.setLinearVelocityY(getWord(%vel, 1));
else
   %srcObj.setLinearVelocity(%vel);
And then add this somewhere
$maxRunSurfaceAngle = 30;

function isRunSurface(%normal)
{
   // Get the angle of the surface. Assume %normal is normalized.
   %angle = mRadToDeg(mAsin(getWord(%normal, 0)));
   
   if (mAbs(%angle) < $maxRunSurfaceAngle)
      return true;
   else
      return false;
}

That should keep objects from sliding down surfaces with angles less than %maxRunSurfaceAngle (angle of 0 being horizontal), but still keep the character from walking through walls.