• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Tutorial] Fix Helicopter

Newbie Spellweaver
Joined
Jun 27, 2016
Messages
12
Reaction score
2
Hey,
just a small fix to the Helicopter physics:

just search for:
Code:
void obj_Vehicle::HelicopterPhysx()

Replace the whole Text with:
Code:
void obj_Vehicle::HelicopterPhysx() // controls of helicopter
{
	PxVec3 NormGravity(0,-9.81,0);
	if (isHelicopter == true)
	{
		const float fTimePassed = r3dGetFrameTime();
		PxTransform pose = vd->vehicle->getRigidDynamicActor()->getGlobalPose();
		r3dVector angles;
		r3dPoint3D position(0,0,0);
		PxVec3 HeliGravity(0,0,0);
		




		if (HasDriver() && HSpeed > 70)
		{
			if (Keyboard->IsPressed(kbsRight)) // Rotate Left
			{
				if (!(Keyboard->IsPressed(kbsW) || Keyboard->IsPressed(kbsS)))
					HelyX+=0.5f;
			}
			else if (Keyboard->IsPressed(kbsLeft)) // rotate Right
			{
				if (!(Keyboard->IsPressed(kbsW) || Keyboard->IsPressed(kbsS)))
					HelyX-=0.5f;
			}
			if (Keyboard->IsPressed(kbsW) && distanceFromGround>=5) // move front
			{
				HeliGravity = PxVec3(0,-1.0,0);
				if (HelyY<15.0f)
					HelyY+=0.5f;
				//HelyUp=-0.1f;




				if (HelyFB>1 && FB>=0)
					FB=HelyFB-=0.25f;
			}
			else {
				if (FB >0 && HelyFB<20)
					FB=HelyFB+=0.05f;




				if (HelyY>0)
				{
					HelyY-=0.5f;
					if (HelyY<0) HelyY = 0;
				}
			}
			if (Keyboard->IsPressed(kbsS) && distanceFromGround>=5) // Move back
			{	
				if (HelyY>-15.0f)
					HelyY-=0.5f;
				
				if (HelyFB>5 && FB<=0)
					FB=abs(HelyFB-=0.5f)*-1;
			}
			else {
				if (FB <0 && HelyFB<20)
					FB=abs(HelyFB+=0.05f)*-1;
				if (HelyY<0)
				{
					HelyY+=0.5f;
				}
			}
			if (Keyboard->IsPressed(kbsD) && distanceFromGround>=10) // move Right
			{
				if (HelyZ>-30.0)
					HelyZ-=0.5f;




				if ((Keyboard->IsPressed(kbsW) || Keyboard->IsPressed(kbsS)))
				{
					HelyX+=0.5f;
				}
				else {
					if (HelyLR>5 && LR>=0)
						LR=HelyLR-=0.5f;
				}
			}
			else {
				if (LR >0 && HelyLR<20)
					LR=HelyLR+=0.1f;
				if (HelyZ<0)
				{
					HelyZ+=0.5f;
				}
			}




			if (Keyboard->IsPressed(kbsA) && distanceFromGround>=10) // move Left
			{
				
				if (HelyZ<30.0)
					HelyZ+=0.5f;




				if ((Keyboard->IsPressed(kbsW) || Keyboard->IsPressed(kbsS)))
				{
					HelyX-=0.5f;
				}
				else {
					if (HelyLR>5 && LR<=0)
						LR=abs(HelyLR-=0.5f)*-1;
				}




			}
			else {
				if (LR <0 && HelyLR<20)
					LR=abs(HelyLR+=0.1f)*-1;




				if (HelyZ>0)
				{
					HelyZ-=0.5f;
					if (HelyZ<0) HelyZ = 0;
				}
			}
			if (Keyboard->IsPressed(kbsSpace) && HSpeed > 70) // move up
			{
				//r3dOutToLog("###### distanceFromGround %f\n",distanceFromGround);
				if (distanceFromGround<100)
				{
					HeliGravity = PxVec3(0,1,0); //m70b1jr gravity
				}
			}
			else if (Keyboard->IsPressed(kbsLeftControl)) // Move down
			{
				if(distanceFromGround< 1)
				{
					HeliGravity = PxVec3(0,-0.1,0);
				}
				else if(distanceFromGround< 0)
				{
					HeliGravity = PxVec3(0,0,0);
				}
				else
				{
					HeliGravity = PxVec3(0,-1,0);
				}
				//HelyUp=-2.0f;
				//HelyUp=-0.1f;
			}
			if (distanceFromGround>0)
			{
				if (!CheckFuel())
				{
					//r3dOutToLog("######## HSpeed: %f\n",HSpeed);
					HeliGravity = PxVec3(0,-9.81f,0);
					//if (HelyUp>0)
					//	HelyUp=-0.1f;
				}
				
			}
		}
		else
		{
			HeliGravity = PxVec3(0,-9.81f,0);
		}


		pose.p.y+=HelyUp;
		if (HelyFB>=20)
			FB=0;
		if (HelyLR>=20)
			LR=0;
		//r3dOutToLog("######## HelyFB: %f FB: %f\n",HelyFB,FB);
		position = r3dPoint3D(pose.p.x,pose.p.y,pose.p.z) + (GetvForw() / FB) + (GetvRight() / LR);
				
        if (isHelicopter == true)
		{
			g_pPhysicsWorld->PhysXScene->setGravity(HeliGravity); // m70 test NormGravity
		}
		else if (isHelicopter != true)
		{
			g_pPhysicsWorld->PhysXScene->setGravity(NormGravity);
		}
		
		
		D3DXMATRIX RotateMatrix,RotateMatrix2,toOrigin,fromOrigin,boneTransform;
		D3DXMatrixTranslation(&toOrigin, -GetPosition().x, -GetPosition().y, -GetPosition().z);
		D3DXMatrixTranslation(&fromOrigin, pose.p.x, pose.p.y, pose.p.z);
		
		D3DXMatrixRotationYawPitchRoll(&RotateMatrix,R3D_DEG2RAD(HelyX),R3D_DEG2RAD(HelyY),R3D_DEG2RAD(HelyZ));
		D3DXMatrixMultiply(&boneTransform, &fromOrigin, &RotateMatrix);




		D3DXMatrixMultiply(&boneTransform, &boneTransform, &toOrigin);




		PxMat33 orientation(PxVec3(boneTransform._11, boneTransform._12, boneTransform._13),
						PxVec3(boneTransform._21, boneTransform._22, boneTransform._23),
						PxVec3(boneTransform._31, boneTransform._32, boneTransform._33));
		pose.q = PxQuat(orientation);




		/*D3DMATRIX m = GetRotationMatrix();*/
		pose.p.x=position.x;//HelyFB;
		pose.p.z=position.z;//HelyLR;
		
		/*HelyLR=position.z;
		HelyFB=position.x;*/
		vd->vehicle->getRigidDynamicActor()->setGlobalPose(pose);
		SetPosition(r3dPoint3D(position.x,pose.p.y,position.z)); //Another test
		r3dPoint3D vel = GetVelocity();
		vel.x *= pose.p.x;
		vel.y *= pose.p.y;
		vel.z *= pose.p.y;
		if(vel.Length() < 0.001f) vel = r3dPoint3D(0, 0, 0);
		SetVelocity(vel);
	}
	else
	{
		g_pPhysicsWorld->PhysXScene->setGravity(NormGravity);
	}
}
 
Last edited:
Junior Spellweaver
Joined
Jan 5, 2015
Messages
173
Reaction score
194
Nice fix , it also adds free invisible jetpack when zombie dies ( ͡° ͜ʖ ͡°)
Dennis Albert - [Tutorial] Fix Helicopter - RaGEZONE Forums
 
Newbie Spellweaver
Joined
Jun 27, 2016
Messages
12
Reaction score
2
Yes :D it's funny, but edited the code for 2 minutes it should fixed now :D
Fixed now.
 
Last edited:
Newbie Spellweaver
Joined
Jun 27, 2016
Messages
12
Reaction score
2
I know there is a tutorial from obama but the helicopter is still a little buggy, so if you use that you cant control it good.
 
Back
Top