Why is CastCollision not working for me?
by John Klimek · in Torque Game Builder · 09/12/2006 (7:15 pm) · 13 replies
I'm confused at how CastCollision is working...
It seems to be returning the collision point as the CURRENT point the object is at.
For example, I have a ball dropping from the sky onto the ground. The ball takes about 20 seconds to reach the ground. About one second into the fall, I run this:
After waiting a few seconds, I run the same castCollision as above.
If I understand correctly, the 3rd and 4th numbers are the vector of the collision point. Instead of being the collision point, they appear to be the CURRENT POSITION of the ball. Is this correct or do I not understand something? I was under the assumption that the collision point would be the point of collision (eg. the point where the ball hits the ground) and so this value wouldn't change everytime I ran castCollision.
It seems to be returning the collision point as the CURRENT point the object is at.
For example, I have a ball dropping from the sky onto the ground. The ball takes about 20 seconds to reach the ground. About one second into the fall, I run this:
$r = $ball.castCollision(60.0); echo($r);
Results: 2137 13.372088 0.000000 16.311237 -0.000000 -1.000000
After waiting a few seconds, I run the same castCollision as above.
Results: 2137 1.283261 0.000000 97.477402 -0.000000 -1.000000
If I understand correctly, the 3rd and 4th numbers are the vector of the collision point. Instead of being the collision point, they appear to be the CURRENT POSITION of the ball. Is this correct or do I not understand something? I was under the assumption that the collision point would be the point of collision (eg. the point where the ball hits the ground) and so this value wouldn't change everytime I ran castCollision.
About the author
Recent Threads
#2
09/13/2006 (4:24 am)
Shouldn't the numbers stay the same though? Regardless of when I call castCollision, the objects are going to collide at the same point...
#3
Basicly what that should do is print out the castCollision info then underneath the X Y value of the object it collided with. You could also add the position of your ball to that code ( $ballvariable.getPosition() ) and echo it out as well. Post it up here because I am semi-interested in what it will return :-)
09/13/2006 (5:38 pm)
You may be right, the way to test (I think this should work) would be using the following code:$r = $ball.castCollision(60.0); echo($r); %obj = getWord($r, 0); %pos = %obj.getPosition(); echo(%pos);
Basicly what that should do is print out the castCollision info then underneath the X Y value of the object it collided with. You could also add the position of your ball to that code ( $ballvariable.getPosition() ) and echo it out as well. Post it up here because I am semi-interested in what it will return :-)
#4
For example, my results:
castCollision reported: 0, 94.633881
Actual position: 0, 94.0292
Another example:
castCollision reported: 0, 111.409309
Actual position: 0, 111.089
I'm beginning to think that castCollision is completely broken...
09/13/2006 (6:01 pm)
Ok, I've tried that and they are almost exactly the same (the collision point and the getPosition). They are off by a few decimal places but I think that's because the simulation is running while the script is running, so when I get the position of the ball it's slightly differently from when I did the collision.For example, my results:
castCollision reported: 0, 94.633881
Actual position: 0, 94.0292
Another example:
castCollision reported: 0, 111.409309
Actual position: 0, 111.089
I'm beginning to think that castCollision is completely broken...
#5
09/13/2006 (8:59 pm)
Ok, from what I understand off another thread I have been responding to, it looks like castCollision is using the position of the entire tile map and not a single tile you are colliding with, which explains the weird values I think.
#6
09/14/2006 (5:52 am)
I'm not using any tile maps...
#7
09/14/2006 (2:34 pm)
Can you define "ground" for me then ?
#8
09/14/2006 (3:42 pm)
It's a custom C++ object called "t2dTerrain". It's basically another t2dStaticSprite.
#9
10/02/2006 (12:54 pm)
Can anybody help me out with this? =(
#10
10/04/2006 (11:11 pm)
Do you have something mounted to your ball perchance? Anything?
#11
10/05/2006 (6:59 am)
Nope, nothing has been mounted to it...
#12
1. castCollision is indeed broken
2. your interpretation of what it should be doing is incorrect
3. your use of the method is incorrect
I usually try to answer that question whenever I'm having trouble with an engine function and every time I have found out that I fell into case 2 or 3 ;)
10/05/2006 (8:13 am)
Have you tried coding a simple, standalone test of cast collision to see if you are using it correctly? Try just putting two square sprites on the screen and bashing them into one another and try some tests. If castCollision still gives you strange results then there are a few possibilities that may get you on the right track.1. castCollision is indeed broken
2. your interpretation of what it should be doing is incorrect
3. your use of the method is incorrect
I usually try to answer that question whenever I'm having trouble with an engine function and every time I have found out that I fell into case 2 or 3 ;)
#13
Note that collision groups and layers are the same as rendering layers. You can set stuff with the following functions:
To set what an object should collide with:
setCollisionGroups(%groups)
setCollisionLayers(%layers)
To set an objects layer and group:
setGraphGroup
setLayer
Basically, you set certain objects to have a specific layer (0-31). Within that layer you can set a specific group to which it belongs (also 0-31). You can then tell other objects to collide with only those objects on that layer and within that group. Basically you can tell the collision system to look at how the items are generally organized to figure out collision.
I had some issues with this stuff too [obviously] when I didn't completely understand the Collision Layers and Groups. If you're not already, it's a good idea to familiarize yourself with the collision functions on the page linked above. CollisionMasks in particular are nice-'n-useful!
Edited for correctness. Collision groups refer to the rendering layers and thus are not separate things.
10/05/2006 (9:59 pm)
Also, are you sure you have your collision groups and layers set correctly? Such that the ball isn't colliding with a background image?Note that collision groups and layers are the same as rendering layers. You can set stuff with the following functions:
To set what an object should collide with:
setCollisionGroups(%groups)
setCollisionLayers(%layers)
To set an objects layer and group:
setGraphGroup
setLayer
Basically, you set certain objects to have a specific layer (0-31). Within that layer you can set a specific group to which it belongs (also 0-31). You can then tell other objects to collide with only those objects on that layer and within that group. Basically you can tell the collision system to look at how the items are generally organized to figure out collision.
I had some issues with this stuff too [obviously] when I didn't completely understand the Collision Layers and Groups. If you're not already, it's a good idea to familiarize yourself with the collision functions on the page linked above. CollisionMasks in particular are nice-'n-useful!
Edited for correctness. Collision groups refer to the rendering layers and thus are not separate things.
Torque Owner Glenn Prince