Game Development Community

Collision and Behaviors

by Teromous · in Torque Game Builder · 04/13/2009 (1:25 pm) · 7 replies

I started using behaviors, and for some reason my collisions don't work for objects that have a behavior attached. As soon as I remove the behavior, collision works fine for the object. I did a search and found that you can use:
%this.owner.collisionCallback = true;
%this.owner.collisionActiveReceive = true;
...but this did nothing when I added it to the onBehaviorAdd function. I'm hoping that somebody else has encountered this issue and has a fix, but I have only seen 1 thread about it and it's in the PSK forums (I can't read it because I'm not a PSK owner).

#1
04/13/2009 (3:49 pm)
I did an onCollision in my behavior, which activates an echo whenever a collision is triggered. Every time my character passes into the collision boundary (the wall), the echo was triggered successfully.

This shows that there is a collision happening, however even when the collision response is set to clamp it does not prevent my character from walking through the wall. It is very frustrating. Any ideas?
#2
04/13/2009 (5:32 pm)
I tried doing a barebones test of behaviors, adding each feature like this:
if (!isObject(TestBehavior))
{
   %template = new BehaviorTemplate(TestBehavior);
   
   %template.friendlyName = "Test Behavior";
   %template.behaviorType = "Test";
   %template.description  = "Test";
}

function TestBehavior::onBehaviorAdd(%this)
{
   echo("Test Behavior Created");
}
Which everything loaded fine, and things could collide with the object. I then tried:
if (!isObject(TestBehavior))
{
   %template = new BehaviorTemplate(TestBehavior);
   
   %template.friendlyName = "Test Behavior";
   %template.behaviorType = "Test";
   %template.description  = "Test";
}

function TestBehavior::onBehaviorAdd(%this)
{
   %this.owner.setLinearVelocityX(-5);
   echo("Test Behavior Created");
}
In this, I wanted to see if movement was causing the collision problem. The object moved across the screen and collided with the wall perfectly. I then tried:
if (!isObject(TestBehavior))
{
   %template = new BehaviorTemplate(TestBehavior);
   
   %template.friendlyName = "Test Behavior";
   %template.behaviorType = "Test";
   %template.description  = "Test";
}

function TestBehavior::onBehaviorAdd(%this)
{
   %this.owner.setLinearVelocityX(-5);
   %this.owner.PlayAnimation(moveWest);
   echo("Test Behavior Created");
}
The object then moved across the screen and passed through the wall. I tried:
%this.owner.SetAnimation(moveWest);
...thinking that this might solve the problem somehow, but it did not. Does anyone have any suggestions that could help?
#3
04/15/2009 (2:36 pm)
Does anyone have a solution to using collisions? I've been looking through the behavior tutorials and I've noticed that the pre-set behaviors cause problems with collisions as well (objects move right through objects that don't have a behavior attached). There has to be something, otherwise it's down the drain with behaviors, and writing everything as scene objects.
#4
04/15/2009 (10:32 pm)
Now I'm not even able to replicate my previous test results. I can't get anything to collide anymore, no matter what I do. Has anyone successfully used collisions with behaviors, in the traditional method where colliding stops movement?
#5
04/16/2009 (2:38 am)
I have collisions working with objects that have behaviours attached, that collide with ones with no behaviours. Im at work now so can't see what the settings are. I think I may have had send and receive for both collisions and physics on the object with the behaviour (a tank), and send for collisions on the non-behaviour object (in this case trees, rocks, that kind of thing).

If I move my tank around, it will collide with the objects, using the collision behaviours that I have specified, so it seems to work fine for me. I don't have animations yet though.
#6
04/16/2009 (9:04 am)
Thanks for replying! You mentioned that it will collide with objects, using the collision behaviors you specify? Are you using onCollision callbacks somehow to prevent the movement of the tank?

I tried using the behavior playground with one object having the behavior of Tank Controls, and send/receive collision selected under the collision drop-down. The other object has no behavior attached, and has send/receive collision selected under the drop-down. The tank drives right through the object.

I then wanted to try something else, so I set the second object to "swap image on collision". When the tank hits the object, the image does swap. What I'm trying to accomplish though, is just regular-old "object collides and stops" like the way things used to work before behaviors.

I guess I could try making a behavior that includes onCollision then reduces x and y velocity to 0 or something...it just seems like a pain to have to assign a behavior to every wall just so I can have the player collide with it, when it used to work just by clicking receive collision...
#7
04/16/2009 (9:35 am)
Well I made a mostly blank behavior for the walls and enabled %this.owner.collisionCallback = true; onBehaviorAdd, then set up:
function TestBehavior::onCollision(%srcObject, %dstObject, %srcRef, %dstRef, %time, %normal, %contacts, %points)
{
   %dstObject.setLinearVelocityX(0);
   %dstObject.setLinearVelocityY(0);
}
Now my character will collide with anything that has this behavior attached. I don't know man...it just seems like a very crude way of doing things...