T3D MIT Control Object
by JeffH · in Torque 3D Professional · 02/18/2013 (9:22 am) · 17 replies
Hey guys,
I was just wondering if someone can point me in the right direction on setting a new control object with a new class. Instead of using the player class, I am wanting to use a new class; for example, the rigidShape class. However, whenever I set the control object via script, the object obviously does not accept player input. Any advice on how to accept player input on other ShapeBase classes?
Thanks,
~Jeff
I was just wondering if someone can point me in the right direction on setting a new control object with a new class. Instead of using the player class, I am wanting to use a new class; for example, the rigidShape class. However, whenever I set the control object via script, the object obviously does not accept player input. Any advice on how to accept player input on other ShapeBase classes?
Thanks,
~Jeff
About the author
19 year old who loves programming with Torque3D!
#2
I haven't done a lot of engine modification as I am more of the script side of things than the hardcore engine side.
Thanks,
Jeff
02/18/2013 (10:31 am)
@ahsan thank you, however I don't think that was what I was looking for... I would like to know how to make the engine recognize other shapebase objects to accept player input and move the object with the movement callbacks. Sorry if I wasn't specific enough. For example, the vehicle and player classes how they can accept key input.I haven't done a lot of engine modification as I am more of the script side of things than the hardcore engine side.
Thanks,
Jeff
#3
02/18/2013 (11:32 am)
Jeff: I suspect this will not be achievable without modifying the engine. What do you want to control instead of a Player or Vehicle? Maybe we can help you find an alternative method if you don't want to dig into the C++.
#4
It would be nice to controls something like the rigid shape class, such as that boulder datablock that exists in script.
02/18/2013 (11:37 am)
Oh I will dig into the c++, I was just saying that I don't have much experience with the engine side of things haha.It would be nice to controls something like the rigid shape class, such as that boulder datablock that exists in script.
#5
02/18/2013 (11:52 am)
Dave Wyand's Marble Motion demo is an excellent example of how to control a RigidShape by applying impulses based on input events.
#6
Thanks,
Jeff
02/18/2013 (12:04 pm)
@Michael Hall thanks, I will look at it. This might be a stupid question that I am asking, but is the source code in the Marble Motion Demo MIT too?Thanks,
Jeff
#7
02/18/2013 (12:08 pm)
The demo is all script, but you will have to update your project from the development branch on Github and re-compile in order to make use of the new functionality as used within it. However, you should still be able to examine the usage of applying impulses from key events and use a similar method in a master branch based project.
#8
mouse:
curMove.pitch = MoveManager::mPitch + pitchAdd;
curMove.yaw = MoveManager::mYaw + yawAdd;
curMove.roll = MoveManager::mRoll + rollAdd;
curMove.x = MoveManager::mRightAction - MoveManager::mLeftAction + MoveManager::mXAxis_L;
curMove.y = MoveManager::mForwardAction - MoveManager::mBackwardAction + MoveManager::mYAxis_L;
curMove.z = MoveManager::mUpAction - MoveManager::mDownAction;
for keyboard:
EnginesourceT3DgameBasemoveManager.cpp
look into "void MoveManager::init()"
that is all about keyboard and mouse.
*************************************
now create a new class following that resource.
then look into:
vehicle.cpp
vehicle.h
wheeledVehicle.cpp
wheeledVehicle.h
look into "void XXXX::updateMove(const Move* move)"
in below these info will save u from analyzing:
move->yaw //when u move mouse movement forward backward
move->pitch //when u move mouse movement left right
move->y //forward backward button input
move->x//left right button input
move->z//up down button input
based on these information i was able to create several type of vehicles and ai animals,aivehicles etc.
02/18/2013 (12:14 pm)
EnginesourceT3DgameBasemoveList.cppmouse:
curMove.pitch = MoveManager::mPitch + pitchAdd;
curMove.yaw = MoveManager::mYaw + yawAdd;
curMove.roll = MoveManager::mRoll + rollAdd;
curMove.x = MoveManager::mRightAction - MoveManager::mLeftAction + MoveManager::mXAxis_L;
curMove.y = MoveManager::mForwardAction - MoveManager::mBackwardAction + MoveManager::mYAxis_L;
curMove.z = MoveManager::mUpAction - MoveManager::mDownAction;
for keyboard:
EnginesourceT3DgameBasemoveManager.cpp
look into "void MoveManager::init()"
that is all about keyboard and mouse.
*************************************
now create a new class following that resource.
then look into:
vehicle.cpp
vehicle.h
wheeledVehicle.cpp
wheeledVehicle.h
look into "void XXXX::updateMove(const Move* move)"
in below these info will save u from analyzing:
move->yaw //when u move mouse movement forward backward
move->pitch //when u move mouse movement left right
move->y //forward backward button input
move->x//left right button input
move->z//up down button input
based on these information i was able to create several type of vehicles and ai animals,aivehicles etc.
#9
02/18/2013 (12:17 pm)
Wow, what a cool addition to the game input lineup! Thanks for pointing this out Michael! I should pay more attention to the fine print in those status updates. I will have to look at other game play options as a result.
#10
However, say if I wanted to do this in c++ so I don't have to go the hackish round with applyImpulse forces. My main issue was that say for the rigid body object, you create an object and you do
and nothing happens with input. Can anyone of you guys point me into the direction of what i need to modify in c++ to accept the movement functions from script? For example, do i need to use class::processTick() to update movement and then pass the Move move to class::updateMove() ? What functions do i need to use in c++ to tell the game "player X wants to move forward when he presses the up key" My goal in the end is to accomplish this in c++, I was just stating that I am not used to the engine and the inter-workings of it.
Edit: oops, I got two posts while typing haha, hang on guys
02/18/2013 (12:18 pm)
Ah, okay, I see how its just haxed with applyImpulse now.However, say if I wanted to do this in c++ so I don't have to go the hackish round with applyImpulse forces. My main issue was that say for the rigid body object, you create an object and you do
localClientConnection.setControlObject(id_of_object_here);
and nothing happens with input. Can anyone of you guys point me into the direction of what i need to modify in c++ to accept the movement functions from script? For example, do i need to use class::processTick() to update movement and then pass the Move move to class::updateMove() ? What functions do i need to use in c++ to tell the game "player X wants to move forward when he presses the up key" My goal in the end is to accomplish this in c++, I was just stating that I am not used to the engine and the inter-workings of it.
Edit: oops, I got two posts while typing haha, hang on guys
#11
02/18/2013 (12:19 pm)
woah, as i was typing i got 2 posts, hang on, don't reply yet haha.
#12
Thanks!!!
~Jeff
02/18/2013 (12:21 pm)
Thanks guys very much for the help, give me some time and I'll post back.Thanks!!!
~Jeff
#13
Now, I cannot give you a definitive answer on this. The reason is because I have not looked at player/vehicle code for years. And that was when I was learning TGE, not T3D.
02/18/2013 (12:30 pm)
Uh, I dunno, maybe the section that says something about input and movement:void Player::processTick(const Move* move)
{
...
// Manage the control object and filter moves for the player
Move pMove,cMove;
if (mControlObject) {
if (!move)
mControlObject->processTick(0);
else {
pMove = NullMove;
cMove = *move;
//if (isMounted()) {
// Filter Jump trigger if mounted
//pMove.trigger[2] = move->trigger[2];
//cMove.trigger[2] = false;
//}
if (move->freeLook) {
// Filter yaw/picth/roll when freelooking.
pMove.yaw = move->yaw;
pMove.pitch = move->pitch;
pMove.roll = move->roll;
pMove.freeLook = true;
cMove.freeLook = false;
cMove.yaw = cMove.pitch = cMove.roll = 0.0f;
}
mControlObject->processTick((mDamageState == Enabled)? &cMove: &NullMove);
move = &pMove;
}
}
...
}Follow the code and see how the pieces fit together. The control object is important. Also remember that there is AI support code in here too. Each object is responsible for acting on input. Just calling something a control object does not make it respond to inputs. Now, I cannot give you a definitive answer on this. The reason is because I have not looked at player/vehicle code for years. And that was when I was learning TGE, not T3D.
#14
02/18/2013 (12:39 pm)
Frank, thank you for your input. I'll be doing some tests in a little bit, I'll see what I can do with all this information. :)
#15
+player side code contains aiplayer related code.
so for starting vehicle related code is best and much easier.
3/4 hour is enough to understand.
as u only interested on movement related code so "updateMove" is more than enough.
but if u want to know how object actually getting orders from engine than look into processTick().otherwise it will be wastage of time when u r looking for only movement.this is only applicable for vehicle code.not for player code
02/18/2013 (6:24 pm)
player side code is much complex than vehicle side code.+player side code contains aiplayer related code.
so for starting vehicle related code is best and much easier.
3/4 hour is enough to understand.
as u only interested on movement related code so "updateMove" is more than enough.
but if u want to know how object actually getting orders from engine than look into processTick().otherwise it will be wastage of time when u r looking for only movement.this is only applicable for vehicle code.not for player code
#16
~Jeff
02/18/2013 (7:17 pm)
thanks ahsan, i'll be looking through that class. Guys if anybody here who has or hasn't posted here yet and wishes to offer advice please do, your only helping as I'm new to the engine. :)~Jeff
#17
I am moving the player by applying impulses via c++ in updateMove based upon player input. However, sometimes my player shape (using a custom class derived from RigidShape) ends up going into the terrain and spazzing out of control, going through the mission area thus causing a crash. Shape seems to bounce a lot (tried modifying the script datablock to get rid some of that bounce (bouncerestitution field)).
If too much impulse is applied, is that normal for a rigid shape to spazz out like that?
I also noticed while debugging my move->yaw in updateMove had been null. Any possible reasons to why it would be registering as null?
Thanks,
~Jeff
02/20/2013 (1:42 pm)
Update: Things have been going better, thanks a lot guys. Anybody know anything about Torque3D's camera system here that could give me some information on that? I am able to get the camera to follow the player, but what about rotation. Should I just use the move->yaw and move->pitch values with some math to do rotation?I am moving the player by applying impulses via c++ in updateMove based upon player input. However, sometimes my player shape (using a custom class derived from RigidShape) ends up going into the terrain and spazzing out of control, going through the mission area thus causing a crash. Shape seems to bounce a lot (tried modifying the script datablock to get rid some of that bounce (bouncerestitution field)).
If too much impulse is applied, is that normal for a rigid shape to spazz out like that?
I also noticed while debugging my move->yaw in updateMove had been null. Any possible reasons to why it would be registering as null?
Thanks,
~Jeff
Ahsan Muzaheed
Default Studio Name