Game Development Community

Page «Previous 1 2 3 Last »
#1
09/02/2008 (1:28 pm)
I'm really sorry that I can't be too detailed, but hopefully someone else can or you can figure this out on your own.

What we did for our game (which is losely based on gameplay from the Diablo/NWN series) is the following:

* When the player clicks on the screen, the coordinates are projected into 3D space and passed on to the MoveManager. The MoveManager packs this position into the next move update. All players get this update as well.
* In updateMove () we use logic from AIPlayer to calculate how much we have to turn to face the position. If it's far away enough, we move there. Since you're using Move updates, the Client will predict as you'd expect and there will be no visible delay when you command your player to go there even if you have lag. That's what we really wanted when we implemented this.

From there you could implement pathfinding and picking up items. Remember, AIPlayer has a lot of the math needed in it already so read trough it and make use of what you can.
#2
09/02/2008 (2:05 pm)
-
#3
09/02/2008 (11:53 pm)
@Callum

In the code you posted above you are getting a normalized 3d point representing a 2d spot you clicked on your GUI. It is crucial to understand that this 3d point is not a representation of a world point. All the 3d point does is help you get what you need. From the code above, you are assuming the 3d point is what you need.

From what you're saying and from the video, you want to make the mouse point into a position on the ground. To do that you need to cast a ray from the 3d point and stop when you hit terrain/interior/ground. You can then use the position you get from the ray to transform your players rotation.

From your above code you can do:
...
if(unproject()) // is the point clicked actually in this GUI
...
// the following gives us our STARTING point.
mMouse3DVec = mouseVec; // this convention is primarily used to make this easily scriptable. You can skip it, 
                                             // but I recommend continuing it.
...
// Next we can either do this in script, or in C++. For simplicity we'll continue in the engine.
// We use our 3d mouse point as the start, and scale that same point for the end.
if(gServerContainer.castRay(mMouse3DVec,mMouse3DVec * 500.0f,SomeTerrainMask,&info))

If the castRay function returns true, we now have the point you want (info.point). This is the position in the world you want your player to face. If you are an AI object, you simply call setAimLocation(info.point).

If you are not an AI object, then you need to set movemanagers yaw. There is a perfect example of how to do this in AIPlayer::getAIMove. The section of code you want is under the comments:

// Orient towards the aim point, aim object, or towards
// our destination.

To be clear, I am sure there are many other ways of doing what you want to do. The example I provided is based on the work you have already done, as I am sure you are already very familiar with those related sections of code.

Let me know how it turnes out!
#4
09/04/2008 (2:30 am)
We have something working right now, originally we modified the gameConnectionMoves files as well, but i've been able to push most of the fun functionality off to this function which overrides the PlayGui. I am assuming you have top down view and you want the mouse to control your yaw.

F32 HnMTSCtrl::getYaw()
{
    GameConnection *con = GameConnection::getConnectionToServer();
    
    if (con->isFirstPerson())
    {
       return 0.0f;
    }

    if (!con->getControlObject())
    {
       return 0.0f;
    }

    GuiCanvas* Canvas = getRoot();

    if (Canvas == NULL)
    {
       return 0.0f;
    }

    // rotate the player to look at where the mouse pointer is pointing to
	// If in 3rd person
	F32 yaw, pitch;
	Point2I point = Canvas->getCursorPos();
	Point2I size =Canvas->getWindowSize();
	Point2I center = size / 2;

	// get the vector for the mouse pointer from the center of the screen
   MatrixF camTrans = con->getCameraObject()->getRenderTransform();      
		 
	VectorF camF;
   camTrans.getColumn(1, &camF);
   VectorF newVec;

   // Check if camera is straight down or on an angle
   if (mFabs(camF.z) == 1.0f) 
   {
      newVec = VectorF(-(point.y - center.y), -(point.x-center.x), 0.0f);
   }
   else 
   {
      newVec = VectorF(point.x-center.x, -(point.y-center.y), 0.0f);
   }
		
		// get the yaw of the vector
   MathUtils::getAnglesFromVector(newVec, yaw, pitch);

	
   MatrixF conTrans = con->getControlObject()->getWorldTransform();

	// get the current rotation around the Z-axis
	F32 curYaw = conTrans.toEuler().z;

   yaw = curYaw + yaw;

	// Check if we are taking the correct way round
    
	if( yaw > M_PI_F )
   {
      yaw -= M_2PI_F;
   }
   else
   if( yaw < -M_PI_F )
   {
      yaw += M_2PI_F;
   }
  			
	return yaw;
}

If you have afx installed, it does the job of passing events through the so that the actionmap can get at it. All it all I think this is a better solution as it allows input to be handle at the correct input end. Make sure you have this:
GuiCanvas* Canvas = getRoot();
    Canvas->setConsumeLastInputEvent(false);

in your onMouseMove.

Doing this you just have to modify your default.bind.cs:
function yaw(%val)
{
   if (ServerConnection.isFirstPerson())
   {
      $mvYaw += getMouseAdjustAmount(%val);
   }
   else
   {
      $mvYaw = PlayGui.getYaw();
   }
}

function pitch(%val)
{
   if (ServerConnection.isFirstPerson())
   {
      $mvPitch += getMouseAdjustAmount(%val);
   }
   else
   {
      $mvYaw = PlayGui.getYaw();
   }
}
#5
09/04/2008 (3:00 am)
That's a good example to follow if you don't want predicted* control object moves, which was a big deal for us. With low ping you won't notice, but with higher ping the latter will be smoother.

[* Where moves are used on the controlling clients machine before they are processed by the server, giving a smoother look.]
#6
09/04/2008 (8:34 am)
-
#7
09/04/2008 (9:38 am)
Hey Callum,
it looks to me like you could prolly do this where you are doing it now just change yaw to MoveManager::yaw

i could be wrong but give it a shot.
#8
09/04/2008 (9:55 am)
It works
#9
09/04/2008 (9:56 am)
In afxTSCtrl.cpp
add
#include "math/mathUtils.h"

replace onMouseMove with
void afxTSCtrl::onMouseMove(const GuiEvent& evt)
{
	//TCASTAGNA
	GameConnection *con = GameConnection::getConnectionToServer();
    
    if (con->isFirstPerson())
    {
       return;// 0.0f;
    }

    if (!con->getControlObject())
    {
       return;// 0.0f;
    }

    GuiCanvas* Canvas = getRoot();

    if (Canvas == NULL)
    {
       return;// 0.0f;
    }

    // rotate the player to look at where the mouse pointer is pointing to
	// If in 3rd person
	F32 yaw, pitch;
	Point2I point = Canvas->getCursorPos();
	Point2I size =Canvas->getWindowSize();
	Point2I center = size / 2;

	// get the vector for the mouse pointer from the center of the screen
   MatrixF camTrans = con->getCameraObject()->getRenderTransform();      
		 
	VectorF camF;
   camTrans.getColumn(1, &camF);
   VectorF newVec;

   // Check if camera is straight down or on an angle
   if (mFabs(camF.z) == 1.0f) 
   {
      newVec = VectorF(-(point.y - center.y), -(point.x-center.x), 0.0f);
   }
   else 
   {
      newVec = VectorF(point.x-center.x, -(point.y-center.y), 0.0f);
   }
		
		// get the yaw of the vector
   MathUtils::getAnglesFromVector(newVec, yaw, pitch);

	
   MatrixF conTrans = con->getControlObject()->getWorldTransform();

	// get the current rotation around the Z-axis
	F32 curYaw = conTrans.toEuler().z;
	
   yaw = curYaw + yaw;

	// Check if we are taking the correct way round
    
	if( yaw > M_PI_F )
   {
      yaw -= M_2PI_F;
   }
   else
   if( yaw < -M_PI_F )
   {
      yaw += M_2PI_F;
   }
MoveManager::mYaw = yaw;
}
#10
09/04/2008 (10:04 am)
Its still a little off but pretty close.
#11
09/04/2008 (10:52 am)
-
#12
09/04/2008 (11:01 am)
Yea, its really close though. just a little tweak here and there should fix it. changing
Point2I point = Canvas->getCursorPos();
to
Point2I point = evt.mousepoint;

helps a little.
#13
09/04/2008 (11:37 am)
-
#14
09/04/2008 (11:50 am)
I'm using advanced camera so mine does not rotate.
#15
09/04/2008 (11:53 am)
-
#16
09/04/2008 (12:06 pm)
-
#17
09/04/2008 (12:35 pm)
I didnt alter the afx camera at all. i used the advanced camera resource instead.
#18
09/04/2008 (12:46 pm)
-
#19
09/04/2008 (1:56 pm)
Yes i have advanced camera ported over. i think there were only like 2 changes, it was really easy. I didn't do anything with afx. just added advanced camera then in game.cs changed what camera it uses. This way if i need to add content (advanced camera does not have fly mode) i can switch back to afx camera and use the fly mode.
#20
09/04/2008 (2:11 pm)
-
Page «Previous 1 2 3 Last »