Controlling a Shape that follows a path
by Gustavo Boni · in Torque Game Engine Advanced · 02/11/2008 (2:05 pm) · 3 replies
Hi everyone,
I have an AiPlayer following a path, but i need to control that. Is AiPlayer the most suitable object for this case? In addition, i wouldn't need all features from the Player, should i create a new class based on ShapeBase for that?
Any help would be greatly appreciated.
Thanks
I have an AiPlayer following a path, but i need to control that. Is AiPlayer the most suitable object for this case? In addition, i wouldn't need all features from the Player, should i create a new class based on ShapeBase for that?
Any help would be greatly appreciated.
Thanks
#2
My point is i dont need the amount of features the Player class provides me. My player just need to follow a path and be controllable, so i was supposing to extend ShapeBase to create a new class only with the information i really need.
Well, i have made some tests, just spawned an aiplayer in a path and set that to be the player. The problems is it doesnt follows the path, only when i change to the cameraFly mode. I dont know how to solve that, let me know if you know, please.
Thanks
02/12/2008 (8:47 am)
Thanks Guimo.My point is i dont need the amount of features the Player class provides me. My player just need to follow a path and be controllable, so i was supposing to extend ShapeBase to create a new class only with the information i really need.
Well, i have made some tests, just spawned an aiplayer in a path and set that to be the player. The problems is it doesnt follows the path, only when i change to the cameraFly mode. I dont know how to solve that, let me know if you know, please.
Thanks
#3
One of the first things that I had to understand when using the TGE is that every object that you want to be able to control (your main character) is in fact a player. So if you are programming a football game it is logical to have 22 AIPlayer objects plus the referees.
Of course, you may consider that a Player is too much for your needs so I would recommend not to touch the player class but to copy the player.cpp and player.h files into... say MyPlayer.cpp and MyPlayer.h then modify them to change all the references to Player or PlayerDatablock to MyPlayer and MyPlayerDatablock... that way you will have a new object called MyPlayer and it should be accessible from the console.
Finally, start the mutilation... remove any portion you really dont want... maybe you dont want froth... cut it... but be careful or you will break the class. Once finished try to create the MyAIPlayer class based on the AIPlayer class.
Now about the AIPlayer not moving. There is a point in the code when the engine requests a movement for a player. The movement may come from the controlling player or, in case of the AIPlayer, from a script. The AIPlayer requests a move only when that player is not in direct control from a player.
So the problem may be that when you are in Camerafly mode your control object is the camera but when you get into playermode the player is in your control so it wont read the AI Script.
Now... the solution may depend in what exactly you want to do... control the object view while it moves through a path maybe?
Luck!
Guimo
02/12/2008 (3:56 pm)
Hi Gustavo,One of the first things that I had to understand when using the TGE is that every object that you want to be able to control (your main character) is in fact a player. So if you are programming a football game it is logical to have 22 AIPlayer objects plus the referees.
Of course, you may consider that a Player is too much for your needs so I would recommend not to touch the player class but to copy the player.cpp and player.h files into... say MyPlayer.cpp and MyPlayer.h then modify them to change all the references to Player or PlayerDatablock to MyPlayer and MyPlayerDatablock... that way you will have a new object called MyPlayer and it should be accessible from the console.
Finally, start the mutilation... remove any portion you really dont want... maybe you dont want froth... cut it... but be careful or you will break the class. Once finished try to create the MyAIPlayer class based on the AIPlayer class.
Now about the AIPlayer not moving. There is a point in the code when the engine requests a movement for a player. The movement may come from the controlling player or, in case of the AIPlayer, from a script. The AIPlayer requests a move only when that player is not in direct control from a player.
So the problem may be that when you are in Camerafly mode your control object is the camera but when you get into playermode the player is in your control so it wont read the AI Script.
Now... the solution may depend in what exactly you want to do... control the object view while it moves through a path maybe?
Luck!
Guimo
Torque 3D Owner Guimo
AIplayer is tha same than a Player object plus some functions which allows it to move from point to point. You can use an AIPlayer instead of a player if you want. Sometimes I have found it useful to force my player to point is a direction.
Luck!
Guimo