Cant get my "scan" function to work
by Daniel Bromfield · in Torque 3D Professional · 05/13/2013 (4:45 am) · 7 replies
im trying to get my npc to search for the player but i keep getting error message
getTransform unknown command???
function AIBasicDB::scan(%aiPlayer){
// transform - A seven-element matrix/vector containing the following information:
// PosX PosY PoxZ RotX RotY RotZ theta (radians)
%transform = %aiPlayer.getTransform();
// Set the x and y rotation axis
%transform = setWord(%transform,3, "0");
%transform = setWord(%transform,4, "0");
// Get the rotational angle measured in radians
%radians = getWord(%transform,6);
// Convert it to degrees
%angle = mRadToDeg(%radians);
// Get the z rotation axis value
%rotationZ = getWord(%transform,5);
// Not sure why but beyond 240 degrees the z rotation axis changes from
// 1 to -1 and the angle changes from 240 to 120 !!!
// This is a work around
if (%rotationZ< 0){
// For an angle between 240 and 360 the engine
// interprits this as 120 to 0. So decrement angle
%angle -= 1.0;
%transform = setWord(%transform,5, "-1");
}
else {
%angle += 1.0;
%transform = setWord(%transform,5, "1");
}
%radians = mDegToRad(%angle);
%transform = setWord(%transform,6, %radians);
%aiPlayer.setTransform(%transform);
}
getTransform unknown command???
function AIBasicDB::scan(%aiPlayer){
// transform - A seven-element matrix/vector containing the following information:
// PosX PosY PoxZ RotX RotY RotZ theta (radians)
%transform = %aiPlayer.getTransform();
// Set the x and y rotation axis
%transform = setWord(%transform,3, "0");
%transform = setWord(%transform,4, "0");
// Get the rotational angle measured in radians
%radians = getWord(%transform,6);
// Convert it to degrees
%angle = mRadToDeg(%radians);
// Get the z rotation axis value
%rotationZ = getWord(%transform,5);
// Not sure why but beyond 240 degrees the z rotation axis changes from
// 1 to -1 and the angle changes from 240 to 120 !!!
// This is a work around
if (%rotationZ< 0){
// For an angle between 240 and 360 the engine
// interprits this as 120 to 0. So decrement angle
%angle -= 1.0;
%transform = setWord(%transform,5, "-1");
}
else {
%angle += 1.0;
%transform = setWord(%transform,5, "1");
}
%radians = mDegToRad(%angle);
%transform = setWord(%transform,6, %radians);
%aiPlayer.setTransform(%transform);
}
#3
Also, it helps us help you if you use the code tags! [ code] and [ /code]
05/13/2013 (5:09 am)
How are you calling the function? Say you have this:function SimObject::doSomething(%arg) {
echo(%arg);
}
MySimObject.doSomething();
ScriptObject::doSomething(MySimObject);Those calls are the same - %arg is MyScriptObject. So if you call this function on a PlayerData datablock, then %aiPlayer is that datablock, and it, of course, doesn't have a transform.Also, it helps us help you if you use the code tags! [ code] and [ /code]
#4
05/13/2013 (5:11 am)
thanx for the reply btw
#5
should i put the whole script here? i call it in another part of my script
%aiPlayer.getDataBlock().schedule(500,"scan",%aiPlayer);
05/13/2013 (5:13 am)
ok im very new to this forum, im a second year uni student so give me time i shall be a pro at making it easier for u!!should i put the whole script here? i call it in another part of my script
%aiPlayer.getDataBlock().schedule(500,"scan",%aiPlayer);
#6
05/13/2013 (6:19 am)
So when the scheduled scan function is called on the datablock, it receives %aiPlayer as an argument - but the first argument is the datablock. So your function should look like this:function AIBasicDB::scan(%datablock, %aiPlayer) {
#7
the datablock should be AIBasic? thats the datablock that holds all the info regarding the AI? thats what i use in all my other functions?
05/13/2013 (7:45 am)
the error message has gone, i put an echo statement in there and it is defo going into the function but its not performing it?the datablock should be AIBasic? thats the datablock that holds all the info regarding the AI? thats what i use in all my other functions?
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
Try writing and see what it gives you.