Jump to content

Camerapick with Bodies?


ParaToxic
 Share

Recommended Posts

Hey Guys , i want to chage in our little FPS Game the bullet as Bodies to Raycasting as in the LE Editor.But somehow it does not work ,to pick Bodies with CameraPick und Add Force to them.

 

I have written :

 

 if(CameraPick( &pick,cam,Vec3(GraphicsWidth()/2,GraphicsHeight()/2,1000),0))
  {
  AddBodyForce(pick.entity,Vec3(0,0,1));  //That is only for testing
  }

 

and i become a error,when i shoot to a oildrum.

Why is that so?

Thank you

Link to comment
Share on other sites

You are picking the mesh, and trying to add force to a mesh. You must add the force to the body instead, which is the parent of the mesh:

if(CameraPick( &pick, cam, Vec3(GraphicsWidth()/2,GraphicsHeight()/2,1000), 0 ))
{
AddBodyForce( GetParent(pick.entity), Vec3(0,0,1) );	//That is only for testing
}

However, if your mesh is in a deeper hierarchy of the model, like a finger attached to a hand attached to an arm attached to the torso, then you need to use GameLib's GetMeshModel(pick.entity) instead of just GetParent(pick.entity).

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Picking only works on the mesh and not the body.

So in your case you try to add a force to a mesh.

 

This function will return the model/body of your picked mesh:

TModel GetMeshModel(TEntity _Entity) 
{
string strClassname;
while (_Entity != NULL) 
{
	strClassname = GetEntityKey(_Entity, "class");
	if (strClassname == "Model") 
	{
		return _Entity;
	}
	_Entity = GetParent(_Entity);
}
return NULL;
};

 

Then you can pick your entity like that:

TEntity GetPickedEntity(TEntity _Entity, float _fRange, TPick& _PickData)
{
TEntity ReturnEntity = NULL;
if (EntityPick (&_PickData, _Entity, _fRange, 0.01F)) 
{            
	ReturnEntity = GetMeshModel(_PickData.entity);
}
return ReturnEntity;
};

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...