Creating a new gameBase-derived object
by Patrick Kemp · in Torque Game Engine · 02/18/2006 (6:07 pm) · 6 replies
Hi guys,
I'm trying to figure out how to make a new gameBase object, but I'm getting pretty intimidated by the engine code. All my object needs to do is accept movement from the mouse and inherit movement from the player (i.e. stay locked relative to the player as the player moves.)
I've already used the info in this thread to handle the mouse movement stuff, but I still don't know how to use the resulting move struct to move my object.
I've tried taking an existing gameBase-derived object like Projectile.cc and stripping it down, but I quickly get lost and don't know what to leave in, take out, or add. If anyone could help me out as far as starting my own gameBase object or stripping down an existing one for my purposes, I'd appreciate it a lot.
Thanks!
I'm trying to figure out how to make a new gameBase object, but I'm getting pretty intimidated by the engine code. All my object needs to do is accept movement from the mouse and inherit movement from the player (i.e. stay locked relative to the player as the player moves.)
I've already used the info in this thread to handle the mouse movement stuff, but I still don't know how to use the resulting move struct to move my object.
I've tried taking an existing gameBase-derived object like Projectile.cc and stripping it down, but I quickly get lost and don't know what to leave in, take out, or add. If anyone could help me out as far as starting my own gameBase object or stripping down an existing one for my purposes, I'd appreciate it a lot.
Thanks!
About the author
#2
02/20/2006 (8:32 am)
You said the object has to be the connection's control object to receive the move? Well, I've got a player object in there that is the control object and that is using the move commands now, and I want this new object to also be movable by the mouse. How could I make it so a second object like the one I'm trying to make receives the move too?
#3
Where myObject is your object's name or ID. The client will then control that object instead of the player.
Be aware that, obviously, the client can only control one object at a time. Since you said something in the likes of "movable by the mouse", I take it you want to do point'n'click control? For that you wouldn't need a move at all, just methods in your object that allow you to set a destination point, and then you update the object position so it moves toward that point every frame.
02/20/2006 (10:17 am)
If you're in "single-player mode" (aka: local connection), type this in the console:localClientConnection.setControlObject([i]myObject[/i]);
Where myObject is your object's name or ID. The client will then control that object instead of the player.
Be aware that, obviously, the client can only control one object at a time. Since you said something in the likes of "movable by the mouse", I take it you want to do point'n'click control? For that you wouldn't need a move at all, just methods in your object that allow you to set a destination point, and then you update the object position so it moves toward that point every frame.
#4
02/20/2006 (12:39 pm)
I'm not shooting for point 'n' click control actually. The secondary object I'm trying to create is a crosshair object, and my game is essentially a 3D sidescroller. So when the mouse moves left and right, the crosshair object should move around. When the keyboard keys are pressed, the player moves around. I'm trying to make the crosshair a seperate object because I've already got it so the player shoots his projectiles at a specific object (via setAimObject.) So I guess if I can only have one control object, I'm not sure how I'd give both the player keyboard commands and the crosshair mouse commands.
#5
There are two ways to do this: with a move and without a move.
If you want to use the move, you can make your player control the crosshair (player.setControlObject(crossHair)).
ShapeBase objects can control other objects. This allows the player to control vehicle, as example. The current player code will create a copy of it's own move, and send it to it's control object. The player will then erase most of the move values, so it can stand still while the vehicle moves.
You'll need to modify the player code (in player.cc, Player::updateMove()) so you pass only the values you want to the crosshair object, and keep only the values the player needs for it.
To do it without a move, modify the gameTSCtrl so it can recieve onMouseMove() calls. There you can read the mouse position, project it into 3D (there is a project() function), and move the crosshair to the desired position (you could either make it call a script function, and move the crosshair there, or something like that). The only problem is that this runs in the client, so you'll have issues accessing the server-side crosshair (you could send commands to server during mouseMove).
02/21/2006 (4:56 am)
Alright, I get it now.There are two ways to do this: with a move and without a move.
If you want to use the move, you can make your player control the crosshair (player.setControlObject(crossHair)).
ShapeBase objects can control other objects. This allows the player to control vehicle, as example. The current player code will create a copy of it's own move, and send it to it's control object. The player will then erase most of the move values, so it can stand still while the vehicle moves.
You'll need to modify the player code (in player.cc, Player::updateMove()) so you pass only the values you want to the crosshair object, and keep only the values the player needs for it.
To do it without a move, modify the gameTSCtrl so it can recieve onMouseMove() calls. There you can read the mouse position, project it into 3D (there is a project() function), and move the crosshair to the desired position (you could either make it call a script function, and move the crosshair there, or something like that). The only problem is that this runs in the client, so you'll have issues accessing the server-side crosshair (you could send commands to server during mouseMove).
#6
As far as creating the actual crossHair object, do you think it'd be better to start from scratch or to modify an existing object? I've tried stripping out Projectile.cc to make my crossHair.cc, but I've only got a vague idea of what each of the standard gameBase functions do, so when it comes down to the specifics I'm not sure what to take out or put in.
Anyway, I understand that this question is pretty unfocused. Hopefully I'll be able to pin my trouble down to more specific questions that are more answerable. At least I've got something to work from now, thanks again!
02/21/2006 (8:44 am)
Awesome, thanks. I think I can handle that.As far as creating the actual crossHair object, do you think it'd be better to start from scratch or to modify an existing object? I've tried stripping out Projectile.cc to make my crossHair.cc, but I've only got a vague idea of what each of the standard gameBase functions do, so when it comes down to the specifics I'm not sure what to take out or put in.
Anyway, I understand that this question is pretty unfocused. Hopefully I'll be able to pin my trouble down to more specific questions that are more answerable. At least I've got something to work from now, thanks again!
Associate Manoel Neto
Default Studio Name
When you get that done, you start dealing with interpolation.