About Store Forum Documentation Contact



Post Reply 
Help on third Person view Camera
Author Message
Otolone Offline
Member

Post: #1
Help on third Person view Camera
Hi there ,
I have this demo.I want my camera to follow my player.But all I get is a black screen.What arguments do I put in my
cam.setFromAt ( ).
Below is my full code

Thanks for any suggestions





/******************************************************************************/
class Player : Game.Chr // extend character class by defining a player class based on the character
{
virtual Bool update() // here we'll update the player (please note that this is a virtual method)
{
// here we update character input according to mouse and keyboard
// before we set the input, we need to check if the character isn't controlled by an automatic action
if(action)
{
// if it's controlled by an action we leave the input with no changes,
// however we can optionally break that action, by pressing for example movement keys
if(Kb.b(KB_W) || Kb.b(KB_S) || Kb.b(KB_A) || Kb.b(KB_D) || Kb.b(KB_Q) || Kb.b(KB_E))actionBreak();
}

if(!action) // if the character isn't controlled by an automatic action, we can set the input
{
// turn & move
input.turn.x=Kb.b(KB_Q)-Kb.b(KB_E);
input.turn.y=Kb.b(KB_T)-Kb.b(KB_G);
input.move.x=Kb.b(KB_D)-Kb.b(KB_A);
input.move.z=Kb.b(KB_W)-Kb.b(KB_S);
input.move.y=Kb.b(KB_SPACE)-Kb.b(KB_LSHIFT);

// dodge, crouch, walk, jump
input.dodge = Kb.bd(KB_D)-Kb.bd(KB_A);
input.crouch= Kb.b (KB_LSHIFT);
input.walk = Kb.b (KB_LCTRL );
input.jump =(Kb.bp(KB_SPACE) ? 3.5 : 0);

// mouse turn
Flt max=DegToRad(900)*Time.d();
angle.x-=Mid(Ms.d().x*1.7, -max, max);
angle.y+=Mid(Ms.d().y*1.7, -max, max);
}

return super.update(); // call Game.Chr.update on which Player is based on
}
}
/******************************************************************************/
Game.ObjMap<Game.Item> Items; // container for item objects
Player player; // container for character objects
/******************************************************************************/
void InitPre()
{
EE_INIT();
App.flag=APP_MS_EXCLUSIVE;

Cam.dist =5;

}
/******************************************************************************/
bool Init()
{
Physics.create(EE_PHYSX_DLL_PATH);

// set world active range to match the view range
Game.World.activeRange(D.viewRange());

// we need to tell the world 'which class handles which object type'
// this is done by assigning memory containers to certain Object Types
Game.World.setObjType(Items, OBJ_ITEM) ; // set 'Items' memory container for 'OBJ_ITEM' objects
player.create(*ObjectPtr(UID(2405352190, 1138949245, 2831971760, 169653295))); // create player from object parameters

// now when the engine is set up properly we can start a 'new game' with a builded world
Game.World.New(UID(1897616802, 1297798754, 1855197886, 2782623339)); // create the world by giving path to world

if(Game.World.settings().environment) // if the world has environment settings (like sun, ambient, sky, ..)
Game.World.settings().environment->set(); // then set them

// which updates world to use only terrain and objects at given position, here camera position is used
Cam.setFromAt(player.pos()-Cam.dist, player.pos(), 0); // update camera according to player angles and mouse wheel


return true;

}
/******************************************************************************/
void Shut()
{
}
/******************************************************************************/
bool Update()
{
if(Kb.bp(KB_ESC))return false;


Physics.startSimulation().stopSimulation();

player.update(); // update player

// which updates world to use only terrain and objects at given position, here camera position is used
Cam.setFromAt(player.pos()-Cam.dist, player.pos(), 0); // update camera according to player angles and mouse wheel
// camera
// set spherical camera with 'look at' position, angles and distance
Cam.updateVelocities( ); // after camera settings are up, we need to update camera velocities in order to achieve correct motion blur when enabled
Cam.set ( ); // set as active camera


return true;

}
/******************************************************************************/
void Render()
{
Game.World.draw(); // draw world (this is done outside of 'switch(Renderer())' because world automatically detects active rendering mode)
}
void Draw()
{
Renderer(Render);
}
/******************************************************************************/
11-08-2015 06:42 PM
Find all posts by this user Quote this message in a reply
Tottel Offline
Member

Post: #2
RE: Help on third Person view Camera
Hi there,

I would recommend taking a look at the tutorial: 14 - Camera Modes.

But at a first glance, you are subtracting Cam.dist from your player position. Player pos is a Vec, Cam.dist is a float.
If you want to use setFromAt; calculate a position behind the player first for the From. Then for the At: That same position + normalized vector in the direction of the player
11-09-2015 07:34 AM
Find all posts by this user Quote this message in a reply
Post Reply