Chasing a sprite?
by Isaac Barbosa · in Torque Game Builder · 01/31/2007 (7:48 am) · 6 replies
Hello TGB growing community :)
I have been reading through the whole documents to check if there is a method to do this but isn't at all:
So I want to ask for some directions if somebody have done this before, I have a static sprite moving all over the stage, another static sprite is shooting some balls at random directions and speeds, but I want that those balls chase after the moving sprite... is this possible? I need to script some kind of AI?
Thanks for the help, as always very useful ;)
Isaac
I have been reading through the whole documents to check if there is a method to do this but isn't at all:
So I want to ask for some directions if somebody have done this before, I have a static sprite moving all over the stage, another static sprite is shooting some balls at random directions and speeds, but I want that those balls chase after the moving sprite... is this possible? I need to script some kind of AI?
Thanks for the help, as always very useful ;)
Isaac
#2
01/31/2007 (8:18 am)
I found moveTo thanks to another thread... I'm looking at the docs now :) As you say Ben, that's exactly what I want to do! Thanks
#3
hum... I'm trying this but I'm getting an error in the last line... what could be wrong?
01/31/2007 (8:23 am)
%this.targetX = $hammer.getPositionX(); %this.targetY = $hammer.getPositionY(); %this.speed = 20; %this.moveTo(%targetX, %targetY, %speed, [%autoStop = true], [%callback = false], [%snap = true], [%margin = 0.1]);
hum... I'm trying this but I'm getting an error in the last line... what could be wrong?
#4
01/31/2007 (9:25 am)
You can't put [] around your arguments. Those [] mean the parameter is optional. Also your %targetX and %targetY (and %speed) are not initialized because you are making them vars on the object. Try more like this:%targetX = $hammer.getPositionX(); %targetY = $hammer.getPositionY(); %speed = 20; %this.moveTo(%targetX, %targetY, %speed);
#5
So this code has to be outside of the object? like a global variable?
01/31/2007 (10:09 am)
Hum...So this code has to be outside of the object? like a global variable?
#6
Thanks Ben, my problem was the $ now is working :)
01/31/2007 (11:39 am)
%targetX = Hammer.getPositionX(); %targetY = Hammer.getPositionY(); %speed = 20;
Thanks Ben, my problem was the $ now is working :)
Torque Owner Ben R Vesco
If you just want to always move toward the target's current position you could set a moveTo every tick with the target's position as the destination.