Setting a Shapebase's aim location
by Nathan Kent · in Torque Game Engine · 01/16/2008 (2:34 pm) · 7 replies
I'm trying to make a third person crosshair, and I just need to find out how to set the shapebases aim location. Here's a sample of what I'm trying to do:
I'm not sure how to get it so I can set an aim location for the player though. One where you can rotate the player as normal, but the place where the player would aim, is the place that the crosshair says it should. Is anyone confused? I'm thinking something like the AIPlayer's setAimLocation, but I'm not sure if would allow you to rotate that camera or not.
void GuiCrossHairHud::onRender(Point2I offset, const RectI &updateRect)
{
// Must have a connection and player control object
GameConnection* conn = GameConnection::getConnectionToServer();
if (!conn)
return;
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & ObjectMask))
return;
// Parent render.
Parent::onRender(offset,updateRect);
// Get control camera info
MatrixF cam;
Point3F camPos;
conn->getControlCameraTransform(0,&cam);
cam.getColumn(3, &camPos);
// Extend the camera vector to create an endpoint for our ray
Point3F endPos;
cam.getColumn(1, &endPos);
endPos *= gClientSceneGraph->getVisibleDistance();
endPos += camPos;
// Collision info. We're going to be running LOS tests and we
// don't want to collide with the control object.
static U32 losMask = TerrainObjectType | InteriorObjectType | ShapeBaseObjectType;
control->disableCollision();
RayInfo info;
if (gClientContainer.castRay(camPos, endPos, losMask, &info)) {
// Hit something... but we'll only display health for named
// ShapeBase objects. Could mask against the object type here
// and do a static cast if it's a ShapeBaseObjectType, but this
// isn't a performance situation, so I'll just use dynamic_cast.
ShapeBase* obj = dynamic_cast<ShapeBase*>(info.object)
if (obj)
if (obj->getShapeName()) {
offset.x = updateRect.point.x + updateRect.extent.x / 2;
offset.y = updateRect.point.y + updateRect.extent.y / 2;
drawDamage(offset + mDamageOffset, obj->getDamageValue(), 1);
}
// Set the Shapebase's aim location to match where the crosshair says it will be
if (obj->getClassName() == "Player")
obj->setAimLocation(info.point);
}
// Restore control object collision
control->enableCollision();
}I'm not sure how to get it so I can set an aim location for the player though. One where you can rotate the player as normal, but the place where the player would aim, is the place that the crosshair says it should. Is anyone confused? I'm thinking something like the AIPlayer's setAimLocation, but I'm not sure if would allow you to rotate that camera or not.
About the author
#2
Edit-> Will this be possible to integrate with the Advanced Camera resource?
01/18/2008 (4:29 am)
Ok, I'll look into that, thanks!Edit-> Will this be possible to integrate with the Advanced Camera resource?
#3
Edit-> I can't go up or down either, but that might be one of my edits...
01/18/2008 (2:31 pm)
I tried implementing you camera, but I can't get it to work. The crossbow shoots where the camera is pointing, but the camera won't follow the player, and I'm not viewing from the camera. Any suggestions?Edit-> I can't go up or down either, but that might be one of my edits...
#4
If the camera isn't following the player it looks like you forgot to set the camera's target. %myGameCamera.setTargetObject(%myPlayer)
Also, the game camera cannot be "integrated" with the advanced camera but you can (given the patience) implement the changes you need into the Advanced Camera.
01/19/2008 (3:18 am)
Okay, I already answered in the other thread but there is more information here so I'll post more..If the camera isn't following the player it looks like you forgot to set the camera's target. %myGameCamera.setTargetObject(%myPlayer)
Also, the game camera cannot be "integrated" with the advanced camera but you can (given the patience) implement the changes you need into the Advanced Camera.
#5
Edit-> all the script is there. While trying to figure it out, I found that if I go into the world editor, then I have control over my yaw (pitch? up/down) axis, but the aim is still funky. I'll make sure I have a the C++ code now...
01/19/2008 (5:49 am)
I added that. I even tried doing it in-game, but I got no results. I'll redo the script part of it, and see if that solves it.Edit-> all the script is there. While trying to figure it out, I found that if I go into the world editor, then I have control over my yaw (pitch? up/down) axis, but the aim is still funky. I'll make sure I have a the C++ code now...
#6
Make sure advanced camera/afx camera/ etc is all removed/disabled.
Make sure you are setting the connections camera object after setting the control object. This is important.
In the console, check to make sure that the your GameCamera object is the active CameraObject for the GameConnection.
Check to make sure that the player is the camera's target.
If these don't return proper values, check into why.
On another note... You can try game camera 2, it isn't quite complete, there still may be bugs, but it is a lot more stable and has more features.
www.garagegames.com/mg/forums/result.thread.php?qt=69874
01/19/2008 (8:53 am)
If you are merging this resource into an existing code base be sure to carefully check places where you might already be setting/changing the camera.Make sure advanced camera/afx camera/ etc is all removed/disabled.
Make sure you are setting the connections camera object after setting the control object. This is important.
In the console, check to make sure that the your GameCamera object is the active CameraObject for the GameConnection.
// This should echo the active camera's name, if you haven't named your camera // you should do so for debugging purposes echo(LocalClientConnection.getCameraObject().getName())
Check to make sure that the player is the camera's target.
// This should reply with your player's name. echo(LocalClientConnection.getCameraObject().getTargetObject().getName())
If these don't return proper values, check into why.
On another note... You can try game camera 2, it isn't quite complete, there still may be bugs, but it is a lot more stable and has more features.
www.garagegames.com/mg/forums/result.thread.php?qt=69874
#7
01/20/2008 (4:55 am)
Ok, I'll look into that, thanks.
Torque Owner Michael Bacon
Default Studio Name
The little gem you are really trying to find is in ShapeImage.cc and is called "getCorrectedAim".
This method corrects the muzzle vector to point wherever at the center of the screen. You modify it slightly to use your external camera instead of assuming a first person camera.
The above link displays the changes I made for my system.
Also if you search for GameCamera 2.0 you should find a slightly updated version. I still have yet a more complete version of the GameCamera that I have yet to release. Let me know if you need help.