Simple Collisions
by George Fairs · in Torque Game Builder · 02/20/2009 (1:00 pm) · 10 replies
I am currently working on a VERY simple top-down shooter, and I want to be able to have crates, that when the player walks into them, he is stopped, just a simple collision.
Any ideas on how I would go about doing this?
(Oh and if anyone knows how I can create a good quality sprite, like the ones in larvamortus, then please can I have some help on that too)
Any ideas on how I would go about doing this?
(Oh and if anyone knows how I can create a good quality sprite, like the ones in larvamortus, then please can I have some help on that too)
About the author
#2
02/20/2009 (2:06 pm)
Ok, how would I go about learning as much of TorqueScript as possible, and doing this collison in code?
#3
create an an that's a t2dSceneObject (maybe just a static sprite)
enable collision callbacks
create a 2nd object that's a t2dSceneobject (maybe just a static sprite)
then, make one stand still and the other move on a collision course
(just set one at -10,0, the 2nd at 10,0 and give the first a linearvelocity of X of 1)
when they collide, you'll get an onCollision callback, which calls the function (look it up in the TDN)
make sure your onCollision just has an echo or something
This little test would help you make the foundation of a class and it's the kind of coding you'll need to do to see how TGB works internally so you can get the most out of the tools that abstract it away. I have a ton of homework this weekend, but I could put together a zip in about 10 minutes to do this.
Then, when you have this (I'll help you when I'm online), you should expand it on your own to investigate collision groups and layers which are super important for any shooter.
02/20/2009 (3:39 pm)
I'm going to be online later, my IM is in my tag. What you need to do is basically:create an an that's a t2dSceneObject (maybe just a static sprite)
enable collision callbacks
create a 2nd object that's a t2dSceneobject (maybe just a static sprite)
then, make one stand still and the other move on a collision course
(just set one at -10,0, the 2nd at 10,0 and give the first a linearvelocity of X of 1)
when they collide, you'll get an onCollision callback, which calls the function (look it up in the TDN)
make sure your onCollision just has an echo or something
This little test would help you make the foundation of a class and it's the kind of coding you'll need to do to see how TGB works internally so you can get the most out of the tools that abstract it away. I have a ton of homework this weekend, but I could put together a zip in about 10 minutes to do this.
Then, when you have this (I'll help you when I'm online), you should expand it on your own to investigate collision groups and layers which are super important for any shooter.
#4
02/20/2009 (3:40 pm)
Actually, I'm waiting for something at work, so I'll get started on it now.
#5
02/20/2009 (4:07 pm)
OK, it's done. I need to upload it or send it or something, but it's probably the most basic collision test possible.
#6
EDIT: I am trying to write the code, but apart from %this, what else do I need?
02/20/2009 (4:48 pm)
Ok thanks, if you want, I could give you quick upload access to my website? You could then upload the file in a directory... Or if you don't feel safe doing that, you could try FileFront? EDIT: I am trying to write the code, but apart from %this, what else do I need?
#7
I tested it, with two sprite, one with send & receive collision, and callback (named player under scripting), and the other just send & receive collision. Nothing happens, even in the console :(
Edit: My email is stapledpuppet@googlemail.com if you want to send to that
02/20/2009 (5:07 pm)
Would this suffice?:function player::onCollision(%this)
{
echo("hello");
}I tested it, with two sprite, one with send & receive collision, and callback (named player under scripting), and the other just send & receive collision. Nothing happens, even in the console :(
Edit: My email is stapledpuppet@googlemail.com if you want to send to that
#8
02/20/2009 (5:38 pm)
Well, I have done it, surprisingly, by making the moving object have receive collision, and receive physics, and the blocks that it is running into have send collision. Done, and that's without scripting. But one problem, when the block that it collides into moves out the way, the original block 1 stays where it is due to clamping :( so I am gonna create a quick ingame prototype to see if my character can move out the way, unlike stupid box :)
#9
02/20/2009 (5:57 pm)
Sent. Just a super simple collision with nice and clean code.
#10
02/20/2009 (6:05 pm)
Nevermind, Google rejected the ZIP
Torque 3D Owner Jason Ravencroft
Oh, and learn to do it in just code. You'll be better off in the long run.
Using just the editor, you could do what you wanted originally, but you'd really be missing out on an opportunity to learn how TGB really works.