Changing Player Size By Player Control
-
- Posts:11
- Joined:2019-07-23, 08:28
I have been working on implementing a crouch functionality to the engine source code, I have figured out how to change the camera height so the player appears to be crouching, but I am at a lost for how to change the actual collision size of the player. When the player character ducks, the camera perspective will be lowered by 1/2 the collision height and the collision box itself will be halved. How can the collision box of the player character be changed while the game is running?
Re: Changing Player Size By Player Control
Hello,
please give me some time for answering this. I'm currently very busy and will only be able to look into it over the weekend.
I'm very sorry that I cannot reply sooner, but I'll do my best!
please give me some time for answering this. I'm currently very busy and will only be able to look into it over the weekend.
I'm very sorry that I cannot reply sooner, but I'll do my best!
Best regards,
Carsten
Carsten
-
- Posts:11
- Joined:2019-07-23, 08:28
Re: Changing Player Size By Player Control
Carsten,
I have actually figured it out myself, this is the code that does what I want:
Code: Select all
if (PC.IsDown(PCK_Duck ) && !PrevPC.IsDown(PCK_Duck) || !PC.IsDown(PCK_Duck) && PrevPC.IsDown(PCK_Duck)) Ducking = !Ducking;
if (Ducking && !PrevPC.IsDown(PCK_Duck))
{
CamOrigin.z = CamOrigin.z / 2;
CameraTrafo->SetOriginPS(CamOrigin);
WishVelocity = scale(VectorT(Vel.x,Vel.y,0), 0.5);
const BoundingBox3dT& HumanPlayerBoundingBox = CompPlayerPhysics->GetDimensions();
BoundingBox3dT HPBB = HumanPlayerBoundingBox;
HPBB.Max.z = HPBB.Max.z / 2;
const BoundingBox3dT& HPBBn = HPBB;
CompPlayerPhysics->SetDimensions(HPBBn);
}
if (!Ducking && PrevPC.IsDown(PCK_Duck))
{
CamOrigin.z = CamOrigin.z * 2;
CameraTrafo->SetOriginPS(CamOrigin);
WishVelocity = scale(VectorT(Vel.x,Vel.y,0), 1.5);
const BoundingBox3dT& HumanPlayerBoundingBox = CompPlayerPhysics->GetDimensions();
BoundingBox3dT HPBB = HumanPlayerBoundingBox;
HPBB.Max.z = HPBB.Max.z * 2;
const BoundingBox3dT& HPBBn = HPBB;
CompPlayerPhysics->SetDimensions(HPBBn);
}
Rather than making a new thread, I will ask this question here. I am now working on the function that accelerates the player's movement making it so that the player accelerates gradually rather than immediately. Here is the code:
Code: Select all
void ComponentPlayerPhysicsT::ApplyAcceleration(double FrameTime, PosCatT PosCat, const Vector3dT& WishVelocity)
{
const double AirAcceleration = 2.5/FrameTime;//1.5 / FrameTime; //units over time
const double GroundAcceleration = 5.0/FrameTime;//6.0 / FrameTime; //units over time
static double AccelSpeed = 0.000;
double WishSpeed=length(WishVelocity); //this function is called from CompPlayerHuman with WishVelocity set to the current velocity of the player (m_Vel?), the length of the vector is the speed
//Vector3dT WishDir;
//if (WishSpeed>0.001 /*Epsilon*/) WishDir=scale(WishVelocity, 1.0/WishSpeed); // I don't know what this means
// Velocity auf WishDir projezieren um festzustellen, wie schnell wir sowieso schon in WishDir laufen
//double CurrentSpeed = length(m_Vel);//dot(m_Vel, WishDir); //the current speed is the length of the wish velocity?
double Acceleration = 0;
//double AddSpeed = 0;
switch (PosCat)
{
case InAir : // airborn, so little effect on velocity
Acceleration=AirAcceleration;
//AddSpeed=Acceleration;
break;
case OnSolid: Acceleration=GroundAcceleration;
//AddSpeed=Acceleration;
// m_Vel.z=0;
break;
}
//if (Acceleration<=0) return;
AccelSpeed = /*(WishSpeed * FrameTime * Acceleration) +*/ WishSpeed + (Acceleration * FrameTime); //accelerate the wish speed by adding the acceleration units
//if (AccelSpeed>WishSpeed) AccelSpeed=CurrentSpeed - WishSpeed; // ??
m_Vel = m_Vel + (m_Vel - VectorT(AccelSpeed,AccelSpeed,0)); //add the difference to m_Vel, the current player velocity SHOULD be made slightly greater
}
...after further review I see that my code makes no sense. I have found some helpful information elsewhere on the forums explaining what some of the variables and statements mean, but the variable FrameTime remains a mystery to me. What does it represent? What is the potential range of values of TimeFrame?
Re: Changing Player Size By Player Control
Hello,
it's good to hear that you could already solve many of the problems yourself!![Thumb Up :up:](./images/smilies/thumbup.gif)
The code in
In order to increase ground acceleration, it would have been enough to increase the const for the
it's good to hear that you could already solve many of the problems yourself!
![Thumb Up :up:](./images/smilies/thumbup.gif)
FrameTime
is the time that it took to render the previous frame, e.g. 0.03 seconds.The code in
ComponentPlayerPhysicsT::ApplyAcceleration()
computes how much the player's speed must change over FrameTime
, that is, within the time that it took to render the previous frame, to eventually reach WishVelociy
.In order to increase ground acceleration, it would have been enough to increase the const for the
GroundAcceleration
.Best regards,
Carsten
Carsten
Who is online
Users browsing this forum: No registered users and 120 guests