XIXWYRMEXIX Posted June 5, 2016 Share Posted June 5, 2016 Hi, I have been delving into AI with Torque 3D, so that being the case I have been doing some of the different tutorials. I am having a problem with the aim of the bot from Steve Acastors Simple FPS Tutorial. Everything other than the aim of the bot works fine, I can spawn with different weapons (I used the Ryder and Lurker) and spawn at points I specify. The bots function fine, with the console logs showing the thinking echos. The aim of the bot shoots up and to the left completely missing the player target unless the player is almost on top of the bot. I have played with different numerical values in the bot script for aim offset and nothing seems to change or affect the bad aim. I am guessing perhaps it is being overridden somewhere somehow? Any help or information would be great. I am using torque 3.8. Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 5, 2016 Share Posted June 5, 2016 I don't remember having any issuing with the bot aim. You already did this tutorial? http://wiki.torque3d.org/scripter:how-do-i-get-started-with-ai Quote Link to comment Share on other sites More sharing options...
XIXWYRMEXIX Posted June 5, 2016 Author Share Posted June 5, 2016 I did that tutorial ages ago (literally years ago). I am doing Steves Acastors Simple FPS. I realize it is made for 1.2 (which I own) but I am attempting it on 3.8. As I said everything else works perfectly. Here is the function-01.function AIPlayer::attackTarget(%this, %target) 02.{ 03. echo(%this.getname() @ " attacking!"); 04. %this.setAimObject(%target, "0 0 1.5"); 05. %this.schedule(150, "shoot"); 06. // a slight delay to make sure we're aiming at the target 07. //you could always use a raycast to see if the target is in the bot's sights instead 08.} 09. It does not matter what value I place, or where in the offset parameters, the Bot always and only shoots up and to the left. I have changed the value to 1, to .75 to 2, there is no perceptible change. Either something changed between 1.2 and 3.8 or I am missing something somewhere. Probably the latter. That's why I was asking about the aim offset being over ridden somewhere, somehow. To me it does not make sense. According to what I have researched, the tutorials I have done and what I know of the setAimObject I should not have this issue. And I should be able to edit the offset and see a difference. So it seems either something has changed, or I am missing something somewhere. Quote Link to comment Share on other sites More sharing options...
XIXWYRMEXIX Posted June 5, 2016 Author Share Posted June 5, 2016 Just did a quick test with the console commands and spawning a bot. The problem is still there with console commands. The setAimObject seems to not work with the console commands either. I have not changed anything in the game other than the tutorial bot scripts so this is a stock 3.8 level with nothing in it except the terrain. I am perplexed. Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 5, 2016 Share Posted June 5, 2016 ok let me check in my t3d v3.8 because I'm remember doing this "3.5) Bob has pretty poor aim" from the wiki tutorial that I give you. Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 6, 2016 Share Posted June 6, 2016 btw you saw this thread? AIPlayer weapon aim bug - http://www.garagegames.com/community/forums/viewthread/143213 Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 6, 2016 Share Posted June 6, 2016 Check eyeoffset: http://garagegames.com/community/resources/view/21614/1 datablock ShapeBaseImageData(AiLurkerWeaponImage) { // Basic Item properties shapeFile = "art/shapes/weapons/Lurker/TP_Lurker.DAE"; emap = true; imageAnimPrefix = "Rifle"; // Specify mount point & offset for 3rd person, and eye offset // for first person rendering. mountPoint = 0; firstPerson = false; useEyeNode = false; animateOnServer = false; eyeOffset = "0.0 0.6 -0.1"; // right/left forward/backward, up/down //... Quote Link to comment Share on other sites More sharing options...
rlranft Posted June 6, 2016 Share Posted June 6, 2016 Eye offset is one option - I just modified WeaponImage::onFire() to get the muzzle point and calc the aim vector from that for AI units:function WeaponImage::onFire(%this, %obj, %slot) { //echo("\c4WeaponImage::onFire( "@%this.getName()@", "@%obj.client.nameBase@", "@%slot@" )"); // Make sure we have valid data if (!isObject(%this.projectile)) { error("WeaponImage::onFire() - Invalid projectile datablock"); return; } // Decrement inventory ammo. The image's ammo state is updated // automatically by the ammo inventory hooks. if ( !%this.infiniteAmmo ) %obj.decInventory(%this.ammo, 1); // Get the player's velocity, we'll then add it to that of the projectile %objectVelocity = %obj.getVelocity(); %numProjectiles = %this.projectileNum; if (%numProjectiles == 0) %numProjectiles = 1; if (%obj.isMemberOfClass("AIPlayer") && isObject(%obj.target)) { %vec = %obj.getVectorTo(%obj.target.position); if(%obj.aimOffset) %vec = VectorAdd(%vec, "0 0 "@%obj.aimOffset); %vec = VectorNormalize(%vec); } else { // getting the straight ahead aiming point of the gun %vec = %obj.getMuzzleVector(%slot); } for (%i = 0; %i < %numProjectiles; %i++) { if (%this.projectileSpread) { // We'll need to "skew" this projectile a little bit. We start by // Then we'll create a spread matrix by randomly generating x, y, and z // points in a circle %matrix = ""; for(%j = 0; %j < 3; %j++) %matrix = %matrix @ (getRandom() - 0.5) * 2 * 3.1415926 * %this.projectileSpread @ " "; %mat = MatrixCreateFromEuler(%matrix); // Which we'll use to alter the projectile's initial vector with %muzzleVector = MatrixMulVector(%mat, %vec); } else { // Weapon projectile doesn't have a spread factor so we fire it using // the straight ahead aiming point of the gun %muzzleVector = %vec; } // Add player's velocity %muzzleVelocity = VectorAdd( VectorScale(%muzzleVector, %this.projectile.muzzleVelocity), VectorScale(%objectVelocity, %this.projectile.velInheritFactor)); // Create the projectile object %p = new (%this.projectileType)() { dataBlock = %this.projectile; }; %p.initialVelocity = %muzzleVelocity; %p.initialPosition = %obj.getMuzzlePoint(%slot); %p.sourceObject = %obj; %p.sourceSlot = %slot; %p.client = %obj.client; %p.sourceClass = %obj.getClassName(); MissionCleanup.add(%p); } }I then added this AIPlayer method:function AIPlayer::getVectorTo(%this, %target) { if (getWordCount(%pos) < 2 && isObject(%target)) %pos = %target.getPosition(); %z = getWord(%this.boundingBox, 2) / 2; %offset = "0 0" SPC %z; %vec = VectorAdd(%offset, %this.getPosition()); %z = getWord(%target.boundingBox, 2) / 2; %offset = "0 0" SPC %z; %pos = VectorAdd(%offset, %pos); return VectorSub(%pos, %vec); } Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 6, 2016 Share Posted June 6, 2016 @rlranft you fix would be merge with the main branch? Quote Link to comment Share on other sites More sharing options...
rlranft Posted June 7, 2016 Share Posted June 7, 2016 Well, I doubt it - it's only necessary (or useful) if a game uses AIPlayer. If not, it's just extra work. Quote Link to comment Share on other sites More sharing options...
XIXWYRMEXIX Posted June 7, 2016 Author Share Posted June 7, 2016 @Johxz- Yes I found that forum post just after my last post here. obviously something is wrong with the setAimObject. Thank you for the link I will look into that as a possible solution/band aide. I was planning on finding other target solutions anyway, I suppose this just bumps up the timeline on that.@rlranft- Thank you for showing me your solution to this issue, I will check into using that or something similar as a solution as well as checking out the eyeoffset. As an aside to you I will be doing some of your tutorials next, just wanted to thank you for providing them. Out of a bit of concern is this going to be fixed soon? It does not bother me personally much, as I have been playing around with Torque off and on for years now, I love the engine. Spent most of the previous time learning about art assets and level/mission design, looking into the AI stuff now. I could see how a Torque beginner might find this extremely frustrating as the setAimObject is one of the few actual AI functions in Torque. To find it broken could turn off beginners from using the engine or learning more about it. I consider myself a beginner with Torque still, but I am happy with the engine, and I view problems like this as another way to learn more about Torque, and Torque scripting. I have been having a blast learning about basic AI scripting and I am now designing my own. Thank you for responding you have both helped me out a lot. Quote Link to comment Share on other sites More sharing options...
XIXWYRMEXIX Posted June 7, 2016 Author Share Posted June 7, 2016 Update- I implemented the eyeoffset to the standard lurker just to test and the bots aim and hit now. I will use this for now and check out implementing and developing another solution in the future. At least this allows me to make a prototype level with AIBots that can aim and shoot and hit me. Thanks for the help! Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 7, 2016 Share Posted June 7, 2016 yea something is wrong with the setAimObject I think that fix need to be included. The prototype I did was close combat for than reason I not see this :| I'm glad we can help. turn off beginners from using the engine or learning more about it this is true. As comment a side, the other day I read in Facebook someone said that he is using currently unity3d, but he wished it had some features of torque3d. :roll: :Dif you don't know someone develop a datablock plugin for unity :lol: Quote Link to comment Share on other sites More sharing options...
Johxz Posted June 19, 2016 Share Posted June 19, 2016 To recap. We have 3 options:1) Eye offset: http://garagegames.com/community/resources/view/21614/12) rlranft fix (TS): http://forums.torque3d.org/viewtopic.php?f=11&t=673#p5578 - http://www.garagegames.com/community/forums/viewthread/1432133) Henry Todd fix (C++): https://www.garagegames.com/community/forums/viewthread/130800/1#comment-830179 Quote Link to comment Share on other sites More sharing options...
Johxz Posted July 11, 2016 Share Posted July 11, 2016 the bug is fixed in the current development branch. pull #1657 Quote Link to comment Share on other sites More sharing options...
marauder2k9 Posted March 16, 2017 Share Posted March 16, 2017 I created a function that tells an AI to aim for a node/bone in your mesh, this way u can set different difficulties for different AI one that's a sniper that headshots one that's a basic soldier always goes for body mass etc etc Quote Link to comment Share on other sites More sharing options...
Azaezel Posted March 16, 2017 Share Posted March 16, 2017 https://github.com/Azaezel/Torque3D/commit/c4c758168b8cd1a9337abb87e4650449c5c84b19 have a 4th solution. (note caveats that prevent that from going in as a generalized solution. *could* do the math via scripts, but really, why take the load hit.) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.