onCollision Mount
by rennie moffat · in Torque Game Builder · 01/27/2010 (10:46 am) · 26 replies
I tried this earlier with little success, tho I would think it is possible. Could somebody please tell me if, in theory, I should be able to mount an object to another when they collide.
Thanks.
Thanks.
About the author
My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.
#2
01/27/2010 (12:29 pm)
Keep it simple... Try this, then tweak the 0 0 1 values as needed for position and strength:function pickUpLobsterBaby::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
%dstObject.mount(%srcObject, 0, 0, 1, true);
}
#3
I thought that would do it but no.
::hmmm.
01/27/2010 (1:23 pm)
ok, so even if I have a behavior running it, just plug in values?I thought that would do it but no.
::hmmm.
#4
01/27/2010 (1:28 pm)
this is my code but nothing.function pickUpLobsterBaby::onBehaviorAdd(%this)
{
%this.owner.setCollisionActive(true, true);
}
function pickUpLobsterBaby::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
%dstObject.mount(%srcObject, 0, 0, 1, true);
}
#5
01/27/2010 (1:39 pm)
Have you put an echo in there to verify that the onCollision is being called?
#6
I had
echo(%srcObject)
and I saw a line in the console saying it could not find object 1340,
i looked in my scenegraph and there of course was no object 1340, but I am not sure why it would ask for something that did not exist.
Also, That happened, i ran the basic same code, no changes of note and now no call to 1340 in the console.
slightly perplexed.
01/27/2010 (1:46 pm)
Ok, something very interesting has just happened.I had
echo(%srcObject)
and I saw a line in the console saying it could not find object 1340,
i looked in my scenegraph and there of course was no object 1340, but I am not sure why it would ask for something that did not exist.
Also, That happened, i ran the basic same code, no changes of note and now no call to 1340 in the console.
slightly perplexed.
#7
01/27/2010 (3:19 pm)
Where did you put that echo? Is the onCollision being called?
#8
echo ("oncollision was called");
Make sure the other object you're supposed to be colliding with has collisions turned on.
01/27/2010 (3:22 pm)
You should do what Patrick suggested and dump an echo command in your onCollision callback just to see if it's running. Doesn't have to echo anything in particular, just make sure it's in there:echo ("oncollision was called");
Make sure the other object you're supposed to be colliding with has collisions turned on.
#9
I have been having trouble entering/existing inside a onCollision function for a while now, but I am not sure what to do beyond the small echo call.
01/27/2010 (4:05 pm)
yah it wont return that.I have been having trouble entering/existing inside a onCollision function for a while now, but I am not sure what to do beyond the small echo call.
#10
You need to make sure that both objects that are supposed to be colliding have "Send Collision", "Recieve Collision" and "Callback" active.
They also need to be in the same Collision Group and on the Same Collision Layer. By default, they should be since all are selected.
You can verify this by selecting the object in TGB and going to the Edit tab and the Collision rollout.
01/27/2010 (5:52 pm)
If the echo is not being called, then at least you know that your problem is with the collision.You need to make sure that both objects that are supposed to be colliding have "Send Collision", "Recieve Collision" and "Callback" active.
They also need to be in the same Collision Group and on the Same Collision Layer. By default, they should be since all are selected.
You can verify this by selecting the object in TGB and going to the Edit tab and the Collision rollout.
#11
when you say this, do you mean with in the game while it is being played or with in the actual scripted function?
Also I did click everything, receive, sends are checked, and callback, which wasn't before but it is not mounting.
:?
01/27/2010 (6:22 pm)
Quote:
If the echo is not being called, then at least you know that your problem is with the collision.
when you say this, do you mean with in the game while it is being played or with in the actual scripted function?
Also I did click everything, receive, sends are checked, and callback, which wasn't before but it is not mounting.
:?
#12
then run the game and the two objects collide look at the console and if you see:"The damn collision callback was fired!" then you know it's being called. I know that you know how to do this, I read the thread that Melv taught you how to debug... Come on now...
01/28/2010 (10:45 am)
Put this in:function pickUpLobsterBaby::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
%dstObject.mount(%srcObject, 0, 0, 1, true);
echo("The damn collision callback was fired!");
}then run the game and the two objects collide look at the console and if you see:"The damn collision callback was fired!" then you know it's being called. I know that you know how to do this, I read the thread that Melv taught you how to debug... Come on now...
Quote:I have no idea what you're talking about...
when you say this, do you mean with in the game while it is being played or with in the actual scripted function?
#13
It says that it "couldn't fin/invalid object 1340"
and of course no 1340 in my scenegraph.
The object, (%dst is 2205) and my %src is 2206.
Am plugging away. donations for the needy appreciated.
HAHAHA.
thanks.
01/28/2010 (11:48 am)
Ok So i ran the code it still does not mount but we see the echo.It says that it "couldn't fin/invalid object 1340"
and of course no 1340 in my scenegraph.
The object, (%dst is 2205) and my %src is 2206.
I have no idea what you're talking about...What I meant was is that you had said...
Quote:I was not sure if you mean the problem is with the script, the editor, something (send collision for instance) was not checked, or anyone of the above.
If the echo is not being called, then at least you know that your problem is with the collision.
Am plugging away. donations for the needy appreciated.
HAHAHA.
thanks.
#14
So you know that the collision is being called, that's the most important thing, it tells us that there is a problem with the mount code.
Try this instead:
Also, in the TGB editor, make sure that the object you're trying to mount to has a link point by hovering over the object, clicking on the second button "Edit this object link point" and click somewhere on there so you have a link point.
01/28/2010 (1:11 pm)
Alright Rennie, now we're talking...So you know that the collision is being called, that's the most important thing, it tells us that there is a problem with the mount code.
Try this instead:
%dstObject.mount(%srcObject, "0.001 0", 0, true);
Also, in the TGB editor, make sure that the object you're trying to mount to has a link point by hovering over the object, clicking on the second button "Edit this object link point" and click somewhere on there so you have a link point.
#15
But to no avail.
this thing is not currently doing what I want, I have entered the new line, as you wrote... which by the way, what is the purpose/meaning of "o.oo1 o"?
And yes I have been playing with link points and the collision polygons all along. but nothing.
Help me Roller Jesus, Help me! You are my only hope!
R2D2 Leaves scene.
01/28/2010 (1:22 pm)
Thanks Roller Jesus!But to no avail.
this thing is not currently doing what I want, I have entered the new line, as you wrote... which by the way, what is the purpose/meaning of "o.oo1 o"?
And yes I have been playing with link points and the collision polygons all along. but nothing.
Help me Roller Jesus, Help me! You are my only hope!
R2D2 Leaves scene.
#16
I can't run TGB while I'm work so I've done about all I can do. If I can setup a simple sample on the train home I will.
01/28/2010 (1:33 pm)
"0.001 0" is a position vector, using the 0.001 related to an old TGB bug where "0 0" would fail to mount and since I'm not sure what version you're using, I thought I'd give it a shot.I can't run TGB while I'm work so I've done about all I can do. If I can setup a simple sample on the train home I will.
#17
thank you.
Are you going to get the iPad for your train rides? hah
thanks again,
Ren
01/28/2010 (1:38 pm)
Sounds good man,thank you.
Are you going to get the iPad for your train rides? hah
thanks again,
Ren
#18
This works perfectly for me, the only hangup I had was that the physics should be disabled when the object interact or you get some crazy bouncing stuff.
Here is a link to the TGB project so you can study.
01/28/2010 (5:29 pm)
Alright R2...This works perfectly for me, the only hangup I had was that the physics should be disabled when the object interact or you get some crazy bouncing stuff.
function CollidableObject::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
%dstObject.mount(%srcObject, 1, 1, 0.5, true);
}Here is a link to the TGB project so you can study.
#19
I have,
srcObject (owner of behavior) with collisions, send and receive on, same for dstObject.
Physics are off for both.
But nothing!!! I am going to cry. What gives. How could it not work?!!
01/28/2010 (6:00 pm)
Thanks so much man, and for the link but, this is not working. errrrrr.I have,
srcObject (owner of behavior) with collisions, send and receive on, same for dstObject.
Physics are off for both.
But nothing!!! I am going to cry. What gives. How could it not work?!!
#20
Are you sure the onCollision callback is being called?
01/28/2010 (6:14 pm)
Are you sure you have the checkbox that says "Callback" checked in the scripting rollout? Are you sure the onCollision callback is being called?
Torque Owner rennie moffat
Renman3000
I am running my onCollision() like this.
function pickUpLobsterBaby::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points) { if(dstObj.class $= "lobsterBabyClass") %this.owner.mount(%this.lobsterBaby, %this.xMount, %this.yMount, %this.trackForce, true); }but no luck.