Game Development Community

Am I overlooking an existing method?

by Nathan Huffman · in Torque Game Builder · 12/20/2006 (12:07 am) · 4 replies

To move an object, say a static sprite, from it's current location to a new location, but only to the new location if it would "fit" (based off it's collision polygon and objects around the new location coords).

setPosition and moveTo both have their drawbacks for what I'm trying to accomplish.

#1
12/20/2006 (6:19 pm)
First thing that comes to mind for me would be to use setPosition to place the object where it would end up moving to, and then using castCollision() with an argument of 0.0 to immediately see if it collides with anything at that location. If not, then leave it be (or reset its location and use moveTo to start moving it there). If it does, then you just move it back to where it originally was. This'll all happen before the next render pass so the player won't even see the object move back and forth
#2
12/22/2006 (4:02 pm)
Ah, that's an excellent idea. I would say, "I don't know why I didn't think of that" - but I'm going to blame it on two reasons:

1) Holiday stress
2) You're smarter than me :)

Thanks ;)
#3
12/27/2006 (9:44 am)
Great suggestion Drew. castCollision is a very powerful tool for things such as this :) Glad you got a good answer Nathan :)

btw relax, it's the Holidays, have a good time (of course this is probably coming too late since you posted this before Christmas).
#4
12/29/2006 (4:40 am)
There is another method - pickRect() can be useful. Some hand work assumed.
I've use it because castCollision give me a strange results sometimes.