How to get your NPC to jump
by City University (#0001) · in Torque Game Engine · 11/06/2005 (7:12 pm) · 18 replies
Hi My name is Rehan and I have been building an AI controller for my thesis. I have been having trouble getting my NPC to jump. Ive been going through the forums and havent really found anything that ca help.
I am using the aiGuard resource as a base. In another thread someone suggested that I do the actual jumping in the C++ code by adding a ConsoleMethod to allow you to make an NPC jump from script. So this is what I did:
This goes in engine\game\aiPlayer.cc
and
I believe this to be correct. Is it??
when I use the code
%obj.jump();
in my script I get the error
"unknown command jump."
in the terminal (I get no other errors. What am I doing wrong??
Thanks in advance :)
I am using the aiGuard resource as a base. In another thread someone suggested that I do the actual jumping in the C++ code by adding a ConsoleMethod to allow you to make an NPC jump from script. So this is what I did:
This goes in engine\game\aiPlayer.cc
ConsoleMethod( AIPlayer, jump, void, 2, 2, "()"
"Make the bot jump")
{
if (canJump() == true)
{
object->jump();
}
}and
/**
* makes the bot jump
*
* @param targetObject The object to target
*/
void AIPlayer::jump()
{
if (canJump() == true)
{
mActionAnimation.action = PlayerData::JumpAnim;
setActionThread(mActionAnimation.action,mActionAnimation.forward,false,false);
}
}I believe this to be correct. Is it??
when I use the code
%obj.jump();
in my script I get the error
"unknown command jump."
in the terminal (I get no other errors. What am I doing wrong??
Thanks in advance :)
About the author
#2
as a public function. Also there is a canJump. 'aiPlayer' is a sub-class of the 'player' class and the 'player' class has a function called canJump().
You seem to have got the same problem as me. Am I right in saying that it should have worked, or is there something Im missing. Can anyone else help??
11/07/2005 (9:34 am)
The only line I missed out in aiPlayer.h wasvoid jump();
as a public function. Also there is a canJump. 'aiPlayer' is a sub-class of the 'player' class and the 'player' class has a function called canJump().
You seem to have got the same problem as me. Am I right in saying that it should have worked, or is there something Im missing. Can anyone else help??
#3
11/07/2005 (10:10 am)
Have you done a clean rebuild? That often fixes issues with changes not apparently showing up. You can also try making a really obvious change (insert a crash in a main loop) - if that doesn't take then you've got something wrong in your build process!
#4
11/07/2005 (10:15 am)
Incidentally - why not use the normal jump mechanism and just set a trigger? You're missing any updates to physics, meaning even if you do get the animation to play it'll just switch back to standing right away, nevermind that the player won't move. :)
#5
11/07/2005 (11:14 am)
I have done a clean rebuild and still no luck. Ramen Sama in the post above seems to have had no luck either. What do you mean by your second post. Could you please explain.
#6
11/07/2005 (1:29 pm)
Damn.. i really thought it'd be funny if it took like 500 lines of code to make an npc jump.. City University (#0001), you disappoint me!!! :'(
#7
Can someels tell me why this is not working please!!
11/07/2005 (2:23 pm)
Well the code isnt working yet, so there is still hope!!Can someels tell me why this is not working please!!
#8
11/22/2005 (10:44 pm)
Well, I ran into this error a while back, but it seems like my solution might be a little elementary for someone working on their thesis. Still I offer it. Are you sure that you are rebuilding the right project for the link that you are using. For example, if it says release in the field at the top of visual studio make sure you use the release icon in the example folder. Or if it says debug then use debug. I wrote several console methods a while back, couldn't get them to work even after a clean rebuild. Turns out, I was using the TorqueDemo_Debug icon, but I was rebuilding the release version. Do a .dump() on your aiplayer and see if the jump() method is one of your options. Hope that helps.
#9
11/23/2005 (9:37 am)
Thanks Noah, Ill try that soon. You have to remember im new to this, im learning from scratch so I WILL make stupid mistakes.
#10
I open Torque SDK.sln in visual studio to enter the code.
Whatever is wrong I know its staring me in the face but I cant see it!!
11/23/2005 (11:20 am)
Im using torqueDemo.exeI open Torque SDK.sln in visual studio to enter the code.
Whatever is wrong I know its staring me in the face but I cant see it!!
#11
Just a little suggestion...
Have you checked that canjump() returns true for your AIPlayer?
I suggest that you add a Con::printf() inside your ConsoleMethod to see if it is being called and the return value of canJump() is true.
Hope this helps.
Bye,
Jacopo
11/23/2005 (11:52 am)
Hi.Just a little suggestion...
Have you checked that canjump() returns true for your AIPlayer?
I suggest that you add a Con::printf() inside your ConsoleMethod to see if it is being called and the return value of canJump() is true.
Hope this helps.
Bye,
Jacopo
#12
That should make the bot jump, if %player is it's id.
11/23/2005 (11:57 am)
Have you tried this?%player.setImageTrigger(2,true);
That should make the bot jump, if %player is it's id.
#13
It doesnt seem to be executing the console method. WHY?
Chris Labombard
I have tried this
but my NPC does not jump. I get no errors either. WHY??
11/23/2005 (12:18 pm)
Jacopo De LucaIt doesnt seem to be executing the console method. WHY?
Chris Labombard
I have tried this
%obj.setImageTrigger(2,true);
but my NPC does not jump. I get no errors either. WHY??
#14
Is it a valid id ? Is it the id of the bot you want to jump ? That will tell you if the code to jump is being called for sure.
Go into editor mode... Figure out what the NPC's id is... type numberid.setImageTrigger(2,true);
Does he start jumping ?
11/23/2005 (1:15 pm)
Echo(%obj);Is it a valid id ? Is it the id of the bot you want to jump ? That will tell you if the code to jump is being called for sure.
Go into editor mode... Figure out what the NPC's id is... type numberid.setImageTrigger(2,true);
Does he start jumping ?
#15
when i do numberid.setImageTrigger(2,true); in the console nothing happens
I have resorted to using applyImpulse to get the NPC to jump but this does not animate the NPC and it looks a bit odd.
11/23/2005 (2:16 pm)
It is a valid id. I know for sure cos ive got my npc to shoot fine.when i do numberid.setImageTrigger(2,true); in the console nothing happens
I have resorted to using applyImpulse to get the NPC to jump but this does not animate the NPC and it looks a bit odd.
#16
11/23/2005 (5:15 pm)
I didn't mean to suggest that the mistake was stupid (I made it after all ;) ) I just didn't want to offend you if the suggestion was below your level. Glad to know that your in the learning phase like the rest of us. Did you do the .dump() on the aiplayer. The first thing you need to do is make sure that your console method is even available to call.
#17
By the way I have got my NPC to jump using
%obj.applyImpulse("0 0 0", "0 0 1000");
Its not the best solution but it works. I still want to get this method to work though and also find out why it isnt recognising it.
11/23/2005 (6:31 pm)
It is not. What do I need to do.By the way I have got my NPC to jump using
%obj.applyImpulse("0 0 0", "0 0 1000");
Its not the best solution but it works. I still want to get this method to work though and also find out why it isnt recognising it.
#18
11/23/2005 (6:43 pm)
Run the torqueDemo_DEBUG and do the .dump() to see if the jump method is available for your aiplayer.
Torque Owner Cinder Games
well theres not enough code here for me to do it...
there's no function canjump() in aiplayer as well...
perhaps you can post more of the code? plus you don't show me what should go in .h
::edit::
ok i figured it out and got the function to show up, but when .jump is called... nothing seems to happen, no errors either.