Jump to content

Player Controller Crouching


darrenc182
 Share

Recommended Posts

There is no crouching state for the controller. You can't scale it on the fly and make it work currently. For now I would suggest storing 2 separate character controller at different heights. One for standing and one for crouching. Then swap them when you need them. I wouldn't create them on the fly either. Create them up front and swap them in when needed. It'll be faster and doesn't really use that much memory.

Link to comment
Share on other sites

There is no crouching state for the controller. You can't scale it on the fly and make it work currently. For now I would suggest storing 2 separate character controller at different heights. One for standing and one for crouching. Then swap them when you need them. I wouldn't create them on the fly either. Create them up front and swap them in when needed. It'll be faster and doesn't really use that much memory.

That was suggested earlier, but was wondering if anyone had gotten it working or if there was a way of doing easily through the engine. I'm sure Josh said that he was going to look into this, but I guess he has chosen not to at this point. I did start with the implementation that you suggested above and I will revisit it very soon.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

yes, i got it working ..

 

this is my old demo: http://pavelrydl.cz/software/char_v12.rar

 

in new version, there is a bug with velocity, so, it has strange behaviour, when you are falling and crouching, lol

 

hey wh1sp3r, thanks for the demo. I did get my preliminary implementation done late last night. here are two sets of code, one for the initialization and one the function being called by the crouching event:

 


bool dhPlayer::Init(TVec3 pos)
{
TMaterial alphatest_mat, ammo_sample_mat;
std::vector<int> weapon_list;
str str_alphatest;

if(m_vStartPosition.X == 0.0 && m_vStartPosition.Y == 0.0 && m_vStartPosition.Z == 0.0)
	m_vStartPosition = pos;

//	Create(m_vStartPosition);
PositionEntity(fw.GetMain().GetCamera(), m_vStartPosition);
standing = CreateController(flt(PLAYER_STANDING_HEIGHT), 12.0f, 35.0f);
crouching = CreateController(flt(PLAYER_CROUCHING_HEIGHT), 12.0f);
EntityType(standing, 0);
SetBodyMass(standing, 85);
SetBodyGravityMode(standing, 1);
SetBodyDamping(standing, 50.0f, 50.0f);
SetBodyFriction(standing, 50.0f, 50.0f);

EntityType(crouching, 0);
SetBodyMass(crouching, 85);
SetBodyGravityMode(crouching, 1);
SetBodyDamping(crouching, 50.0f, 50.0f);
SetBodyFriction(crouching, 50.0f, 50.0f);

m_iPlayerStatus = PLAYER_STANDING;
player = standing;
PositionEntity(player, EntityPosition(fw.GetMain().GetCamera()));
EntityType(player, COLLISION_PLAYER);
SetEntityKey(player, "name", "player");

luabind::module(myLuaState) [
   luabind::class_<dhLuaWeaponScript>("dhLuaWeaponScript")
  .def(luabind::constructor<>())
  .def("SetWeaponModel", &dhLuaWeaponScript::SetWeaponModel)
  .def("SetWeaponPosition", &dhLuaWeaponScript::SetWeaponPosition)
  .def("SetWeaponRotation", &dhLuaWeaponScript::SetWeaponRotation)
  .def("SetWeaponFireSpot", &dhLuaWeaponScript::SetWeaponFireSpot)
  .def("SetAttackSound", &dhLuaWeaponScript::SetAttackSound)
  .def("SetReloadSound", &dhLuaWeaponScript::SetReloadSound)
  .def("SetUseSound", &dhLuaWeaponScript::SetUseSound)
  .def("SetWeaponType", &dhLuaWeaponScript::SetWeaponType)
  .def("SetAttackAnimFunc", &dhLuaWeaponScript::SetAttackAnimFunc)
  .def("SetGeneralAnimFunc", &dhLuaWeaponScript::SetGeneralAnimFunc)
  .def("SetMaxClipSize", &dhLuaWeaponScript::SetMaxClipSize)
  .def("SetMaxAmmo", &dhLuaWeaponScript::SetMaxAmmo)
  .def("SetStartAmmoAmount", &dhLuaWeaponScript::SetStartAmmoAmount)
  .def("SetStartClipAmmoAmount", &dhLuaWeaponScript::SetStartClipAmmoAmount)
     .def("PrintWeaponMessage", &dhLuaWeaponScript::PrintWeaponMessage)
  .def("SetReloadDOF", &dhLuaWeaponScript::SetReloadDOF)
  .def("SetReloadDOFStrength", &dhLuaWeaponScript::SetReloadDOFStrength)
  .def("SetFireRate", &dhLuaWeaponScript::SetFireRate)
 ];

luabind::module(myLuaState) [
   luabind::class_<dhLuaPlayerScript>("dhLuaPlayerScript")
  .def(luabind::constructor<>())
  .def("LoadWeapon", &dhLuaPlayerScript::LoadWeapon)
 ];

LoadPlayerScript("abstract::player.lua");

LoadPlayersWeapon(WEAPON_FISTS);

weapon_list = PlayerScript.GetWeaponList();

for(int i=0;i<weapon_list.size();i++)
{
	LoadPlayersWeapon(weapon_list[i]);
}

activation_timer.Initialize();
activation_timer.AddItem(100);				// For turning flashlight on and off.
activation_timer.AddItem(100);				// For switching light (in this case) on and off
g_tCrossHair = LoadTexture("abstract::crosshairb.dds");

//	new_gun.weapon_type = WEAPON_PISTOL;

//	m_tGunList.push_back(new_gun);

//	GUIHealthGroup = LoadTexture("abstract::health_group.dds");
//	GUIHealthUnits[0] = LoadTexture("abstract::trans_test.dds");
//	DrawImage(GUIHealthGroup, 400, 400, 156, 104);

//--g_Renderer.SetCurWorld(WLD_FOREGROUND);	--//
//	fgcam.Create(Vec3(0.0f, 0.0f, 0.0f));
//	alphatest=CreatePlane();

fw.GetTransparency().SetWorld();
CreateAmmoHUD();
CreateHealthHUD();
fw.GetMain().SetWorld();

//	RotateMesh(alphatest, Vec3(-90.0f, 0.0f, 0.0f));
//	RotateMesh(alphatest, Vec3(0.0f, 0.0f, 90.0f));

//	PositionEntity(alphatest,Vec3(1.5, -1.7, 2.5));
//	ScaleEntity(alphatest,Vec3(0.5));
//	alphatest_mat = LoadMaterial("abstract::alphatest.mat");
//	PaintEntity(alphatest,alphatest_mat);
//	HideEntity(alphatest);

//--g_Renderer.SetCurWorld(WLD_MAIN);--//

SetEntityCallback(player, (byte*)EntityCollisionCallback,ENTITYCALLBACK_COLLISION);
SetEntityCallback(player, (byte*)MessageReceiveCallback, ENTITYCALLBACK_MESSAGERECEIVE);
SetEntityCallback(player, (byte*)UpdateMatrixCallback,ENTITYCALLBACK_UPDATEMATRIX);

m_sJump = LoadSound("abstract::jump1.wav");
m_sGrenExplode = LoadSound("abstract::impexp_03.wav");

campivot=CreatePivot();
CreateFlashLight();

PositionEntity(campivot, EntityPosition(fw.GetMain().GetCamera()));

return true;
}

void dhPlayer::Crouch(void)
{
if(m_iPlayerStatus == PLAYER_STANDING)
{
	TVec3 pos = EntityPosition(player);
	m_iPlayerStatus = PLAYER_CROUCHING;
	player = crouching;
	PositionEntity(player, pos);
	EntityType(player, COLLISION_PLAYER);
	EntityType(standing, 0);
	SetBodyGravityMode(standing, 0);
}
else if(m_iPlayerStatus == PLAYER_CROUCHING)
{
	TVec3 pos = EntityPosition(player);
	m_iPlayerStatus = PLAYER_STANDING;
	player = standing;
	PositionEntity(player, pos);
	EntityType(player, COLLISION_PLAYER);
	EntityType(crouching, 0);
	SetBodyGravityMode(crouching, 0);
}

SetEntityKey(player, "name", "player");
SetBodyGravityMode(player, 1);
}

 

The behaviour I am getting is not desirable. I can crouch the first time just fine but standing back up doesn't work very well. The camera slides back down to the crouching position sometimes. I was wondering if any one could suggest a better method or can see something in my code that would create a problem. Thanks in advance.

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

  • 3 weeks later...

Just out of curiousity, could you use one controller and then use the ScaleEntity function on the Y axis to scale the entity to the appropriate crouch or standing, for example when the player crouches could you scaleentity to say 50% of the current y... then scale 200% to go back to standing?

 

Not sure if this would upset the collisions?

 

This is how I did this in GDK, for the Dark Physics controller..

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

function Player()
 local player = {}
 player.activeHeight = 1.8
 player.height = 1.8
 player.crouch = 0.8

 player.radius = 0.45
 player.stepHeight = 0.25
 player.maxSlope = 45.0
 player.mass = 10.0
 player.iteractions = 45.0
 player.jump = 0.0
 player.jumpHeight = 6.0

   function player:Create()
     player.controller = CreateController(player.height, player.radius, player.stepHeight, player.maxSlope, player.iteractions)
     player.controller:SetCollisionType(COLLISION_CHARACTER, 0)
     player.controller:SetMass(player.mass)
     player.controller:SetPosition(fw.main.camera.position)
   end

   function player:Free()
     player.controller:Free()
   end

 return player
end

player = Player()
player:Create()

while KeyHit(KEY_ESCAPE) == 0 do

 if KeyHit(KEY_C) == 1 then
   if player.crouching == true then
     player.crouching = false
     player.controller:SetScale(Vec3(player.controller.scale.x, player.height / 2, player.controller.scale.z))
     player.activeHeight = player.height
   else
     player.crouching = true
     player.controller:SetScale(Vec3(player.controller.scale.x, player.crouch / 2, player.controller.scale.z))
     player.activeHeight = player.crouch
   end
 end

 player.controller:Update(yaw, move, strafe, jump, 40, 10)
end

 

You'll have to fill in the rest. I had retyped this so I apologize for any mistakes. Setting the controller scale works for me. At least it looks like it :)

Link to comment
Share on other sites

Yes and no, actually just scaling the controller to a prone size would be more realistic, since people in prone position are able to turn around in a small corridor, which would not be the case if the controller was laying flat.

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

Yeah, that would work if you're athletic enough for such manouver :)

I would just turn on my side, and try to squeeze my head to the other side, and then the legs.

Of course it also depends if the corridor is more broad than high.

If the corridor is quite small in both dimensions, you'd use the diagonal space and squeeze your head, and one leg at a time to the other side.

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

It's funny, I was reading through this thread, and thinking well I am looking at a minimum of 3 controllers... maybe more if your character is say a biped thatn walk 2 legs, 4 legs, crouch, prone, etc...

 

Having the ability to set different controller modes and associated X Y Z dimensions would be very helpful...

 

So I guess the next question is, When is 2.31 going to be available :)

If it's not Tactical realism then you are just playing..

Link to comment
Share on other sites

How do you use the ControllerCrouched function? I know it is similar to the ControllerAirborne function, but with the ControllerAirborne you can apply a force to the controller to get the player to jump, but what do you have to do to the controller when the ControllerCrouched passes 0 back to the calling function?

Intel 2nd Generation i5 Quad Core Running at 3.30GHz. 8GB RAM, GeForce GTX 460 1024MB DDR5.

Link to comment
Share on other sites

Could the crouchmode be a float instead of int, so I could say how much it should crouch, and don't need to recreate the controller for different heights?

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

Yes a float for the the new height would be cool, although if this is availabe next thing you will need is to change controller orientation... crouching is not so much an issue, but to make prone realistic you would need to basically rotate the controller mesh by 90degrees to simulate lying down..

 

I know this is growing outside scope but height and orientation would be nice... so for crouch you can set the height, but for prone you can set the height normal but set the rotation to 90... or 1 for 90 degree rotation, I am sure this will create a whole bunch of issues but it was just a suggestion... :P

If it's not Tactical realism then you are just playing..

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...