Simple Trigger question
by David Ravel · in Torque Game Builder · 02/05/2009 (5:44 pm) · 5 replies
So what I've done is I've mounted a camera to a scene object and the camera is locked to the object's world limit. This way the camera stays in one place but whenever the player reaches the edge of the camera he hits a trigger. What I want is that when he hits this trigger a function is called that tells the camera's scene object to moveto some predetermined coordinates. I'm really new with scripting. I'm using the mount camera behavior to get the camera onto the object. I've got the datablock for the trigger made, but I'm not sure how to get the trigger to tell the scene object to move across the screen.
Thanks for your help guys.
Thanks for your help guys.
#2
now you can create the following code in script
$cameraWidth=400;
function screenMoveTrigger::onEnter(%this, %obj)
{
camera.moveto(%obj.getPositionX+($cameraWidth/2), camera.getPositionY);
}
now that code will not work.. but if you look at the move to function, or something similar, and find out how to the the y position of the camera, etc it should work easily. Feel free to keep posting on this space when you get caught up and i'll help you though it.
cheers!
-nic
02/17/2009 (9:30 am)
I don't have alot of time to answer this question, but I can give you a quick idea of what you might want to do. First set up your triggers by going into the tgb editor and creating a new trigger where you want it. Change the "class" name to something like "screenMoveTrigger" and make sure your "onEnter" callback is on.now you can create the following code in script
$cameraWidth=400;
function screenMoveTrigger::onEnter(%this, %obj)
{
camera.moveto(%obj.getPositionX+($cameraWidth/2), camera.getPositionY);
}
now that code will not work.. but if you look at the move to function, or something similar, and find out how to the the y position of the camera, etc it should work easily. Feel free to keep posting on this space when you get caught up and i'll help you though it.
cheers!
-nic
#3
I wound up using this script and it does indeed work.
function frameTrigger::onEnter(%this)
{
cameraMount.moveTo(camerMount.getPositionX+176.25, cameraMount.getPositionY, 20, true, true, true, 0.01);
}
There is only one problem. Originally I chained a couple of these triggers in a row and when I'd walk across the second or third the function would be called and the camera would move again. However, now the second trigger doesn't cause the cameraMount to move. I'm not sure what's up with this. I've thrown in an echo statement to make sure the trigger is getting hit, it's callback is enabled, and it is near identical to the first trigger. I'm going to continue messing around until I find the cause of the bug but any insight you might have would be appreciated.
02/17/2009 (7:03 pm)
Thanks for the help Nic, I've actually been troubleshooting this problem this problem on a more recent topic here: http://www.garagegames.com/community/forums/viewthread/85085I wound up using this script and it does indeed work.
function frameTrigger::onEnter(%this)
{
cameraMount.moveTo(camerMount.getPositionX+176.25, cameraMount.getPositionY, 20, true, true, true, 0.01);
}
There is only one problem. Originally I chained a couple of these triggers in a row and when I'd walk across the second or third the function would be called and the camera would move again. However, now the second trigger doesn't cause the cameraMount to move. I'm not sure what's up with this. I've thrown in an echo statement to make sure the trigger is getting hit, it's callback is enabled, and it is near identical to the first trigger. I'm going to continue messing around until I find the cause of the bug but any insight you might have would be appreciated.
#4
unction frameTrigger::onEnter(%this)
{
cameraMount.moveTo(%this.getPositionX+176.25, cameraMount.getPositionY, 20, true, true, true, 0.01);
}
02/17/2009 (7:47 pm)
um, first of all you need to use your xposition to be the position of the trigger as I sketched out originally. That way you know the camera is moving from the location of the trigger and not your camera. You can also do a check to see what direction your character is moving so you can get the cammera to pan left or right depending on the way he is facing when he enters the trigger. unction frameTrigger::onEnter(%this)
{
cameraMount.moveTo(%this.getPositionX+176.25, cameraMount.getPositionY, 20, true, true, true, 0.01);
}
#5
02/17/2009 (11:26 pm)
I've tried that but still the second instance of the trigger doesn't work. It gets triggered, which I can tell from an echo which I put in the function, but it never moves the cameraMount. What gives? It used to work.
Torque Owner David Ravel