Tile Collisions & more
by Ryan Ackley · in Torque Game Builder · 07/06/2005 (3:26 pm) · 10 replies
Hey guys, thought I'd throw this out there, see if anybody has any insight as to what my issue might be. I'm working on a basic platformer. Im just trying to put together a simple demo, to make sure any technical issues are covered before I really get knee deep. Anyway, heres the current scenario: I've got a player character (type fxAnimatedSprite2D). He's great. He walks left OR right, can jump, the whole 9. I set a world limit with a clamp, so he basically walks along the bottom of the screen. Good so far. So then I decide "hey, wouldn't it be great to have some ground to walk on, jump over, etc?" I figured a Tile Layer would be the best thing. So I load up the tile editor, make some basic ground, save it all up, great. So, using some of the documentation, I get a tile layer in there that I can see. (sorry if this post seems to be rambling, I'm getting to the point soon, I promise). Too bad my character falls right past the tile layer, to the bottom of the screen. So, I setup collisions between my player and the tile layer, no biggie. Script a call back to echo to the console, let me know when the eagle has landed. Load it up again, player falls... straight to the ground. Im using setconstantforce() on my player to simulate gravity. So, in my callback, when the player collides with the tile layer, i call $player.setAtRest(); Seems to do the trick, except gravity keeps accellerating towards the ground, which makes the call back, which makes the player stop moving. Not so good for moving along the tile layer, now is it? I tried various permutations of collisions/disabling gravity/enabling gravity, but nothing seemed to work. Is there a method, property, etc. that I can set on the tile layer to make it "impassable"? I'm sure somebody somewhere has done it, because somebody, somewhere is working on a platformer. I know it! I know it sounds like I'm looking for the "simple" answer, but to me, the solution is not obivous, and the problem is simple. I looked and looked and could not find an answer (even with gg's cool new google mini).
Any suggestions?


kinda get me now?
Any suggestions?


kinda get me now?
About the author
#2
07/08/2005 (8:39 am)
Yeah, i had to read through the docs to figure that out. My problem isn't that I can't detect a collision (infact, many hundreds of collisions happen between the little guy and the tile layer) But, I'm looking for a good way to make him rest on top of the tile, instead of falling through. My guess is that there could be a material that says "you cant pass by/through me" OR some other method, though I am clueless. Any further help would be appreciated! thanks.
#3
Perhaps that is what you're looking for? I'm not absolutely sure myself, but that'd be my guess.
07/08/2005 (9:04 am)
// --------------------------------------------------------------------
// Immovable Collision Material.
// --------------------------------------------------------------------
datablock t2dCollisionMaterialDatablock(immovableMaterial)
{
friction = 0.0;
restitution = 0.0;
relaxation = 0.5;
density = 0.0;
forceScale = 0;
damping = 0.0;
};Perhaps that is what you're looking for? I'm not absolutely sure myself, but that'd be my guess.
#4
07/08/2005 (9:21 am)
Yeah, I tried that, no luck. I guess im going to check out the physics demo, as I have more physics questions as well. should I find the answer to my question, I will post here. Thanks for your help guys.
#5
07/08/2005 (9:27 am)
Did you try the material Justin suggested with .setCollisionPhysics(true, true); on the tile layer ? :)
#6
07/08/2005 (9:39 am)
Yup, i had done that. What my fool self didnt do was set the collision physics for the player. GAH! Thanks matt, your suggestion lead me to my mistake. Now to figure out why hes not moving along the surface, but i believe thats more to do with my materials, etc (and not relevant to a discussion about tiles). Thanks again guys!
#7
07/08/2005 (9:50 am)
Its always the simplest of things :) Glad you got it working, well at least that part of it.
#8
I think its because you are setting him at rest. Try just setting his linear Y velocity to 0 instead. Of course then he could walk through the sides of blocks. What you need to do is check the %normal. It tells you which direction the collision is coming from. If its coming from the side (i.e. GetWord(%normal,0) != 0) then set his x velocity to 0. If the second word != 0 then set the y velocity to 0. If you do that you shouldn't need the physics at all, just collisions.
-Peter
07/08/2005 (11:35 pm)
Quote:Now to figure out why hes not moving along the surface
I think its because you are setting him at rest. Try just setting his linear Y velocity to 0 instead. Of course then he could walk through the sides of blocks. What you need to do is check the %normal. It tells you which direction the collision is coming from. If its coming from the side (i.e. GetWord(%normal,0) != 0) then set his x velocity to 0. If the second word != 0 then set the y velocity to 0. If you do that you shouldn't need the physics at all, just collisions.
-Peter
#9
07/09/2005 (7:57 am)
Thanks peter, I actually figured it out, I had friction set on one of my materials, and that was too high. Soon gonna have a nice framework setup for my platformer.
#10
Is it ok for you to share your code on how you made your character to jump? I've been trying to do the same but unsucessful. I've always loved Mario series and want to do something similar.
Any help are greatly appreciated.
Thanks,
Tri
09/29/2005 (3:03 am)
Hi Ryan,Is it ok for you to share your code on how you made your character to jump? I've been trying to do the same but unsucessful. I've always loved Mario series and want to do something similar.
Any help are greatly appreciated.
Thanks,
Tri
Torque Owner Jesse Hall