Jump to content

force on a body


Rick
 Share

Recommended Posts

How does the force Vec3 work for the force methods? I'm trying to visualize how this would work. Let's say we have a human standing and we wanted to make that human fly upwards and back would the Vec3 be below it's midsection? But wouldn't it need an angle also? Like at it's midsection and pointing slight up so the human would fly back and up?

 

Imagine the human is the character controller. I want to make the controller fly up and "back".

Link to comment
Share on other sites

Yup, then you'd apply a Vec3 like (0, 1, 1) which would be a 45 degree angle if you are using it's local coord system...or it might be -1 for the Z component...Scale the Y and Z to adjust force, so it might be (0, 50, 50) or something.

 

AddBodyForce applies the force to the whole body, so you don't need to worry about applying it to his midsection.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

Link to comment
Share on other sites

OK, so it seems we can't apply forces on the controller. So I'm working on a work around. This works, BUT the body box rotates in the air which messes its orientation up so multiple force applying doesn't always produce the same result. It would be ideal if it didn't spin. Any ideas?

 

 

//	====================================================================
//	This file was generated by Leadwerks C++/LEO/BlitzMax Project Wizard
//	Written by Rimfrost Software
//	http://www.rimfrost.com 
//	====================================================================

#include "engine.h"

int main( int argn, char* argv[] )
{
Initialize() ;
RegisterAbstractPath("C:/Leadwerks Engine SDK");
SetAppTitle( "Test02" ) ;
Graphics( 800, 600 ) ;
AFilter() ;
TFilter() ;

TWorld	world;
TBuffer gbuffer;
TCamera camera;
TMesh	mesh;
TLight	light;
TMesh	ground;
TMaterial material;

world = CreateWorld() ;
if (!world) {
	MessageBoxA(0,"Error","Failed to create world.",0);
	return Terminate();
}

gbuffer=CreateBuffer(GraphicsWidth(),GraphicsHeight(),BUFFER_COLOR|BUFFER_DEPTH|BUFFER_NORMAL);

camera=CreateCamera();
PositionEntity(camera,Vec3(0, 5, -9));
RotateEntity(camera, Vec3(45, 0, 0));

material=LoadMaterial("abstract::cobblestones.mat");

//mesh=CreateCube();
//TBody meshBody = CreateBodyBox();
//EntityParent(mesh, meshBody);
//PositionEntity(meshBody, Vec3(2, 1, 0));
//PaintEntity(mesh,material);
//EntityType(meshBody, 2);
//SetBodyMass(meshBody, 1);

TController controller = CreateController();
EntityType(controller, 3);
SetBodyMass(controller, 1);

//CreateJointFixed(meshBody, controller);

ground=CreateCube();
ScaleEntity(ground,Vec3(10,1,10));
TBody groundBody = CreateBodyBox(10, 1, 10);
EntityParent(ground, groundBody);
PositionEntity(groundBody,Vec3(0,-2,0));
EntityType(groundBody, 1);
PaintEntity(ground,material);

Collisions(1, 2, 1);
Collisions(1, 3, 1);

light=CreateDirectionalLight();
RotateEntity(light,Vec3(45,45,45));

DebugPhysics(1);

TBody meshBody = CreateBodyBox();
RotateEntity(meshBody, Vec3(0, 45, 0));
EntityType(meshBody, 2);
SetBodyMass(meshBody, 1);

// Game loop
while( !KeyHit() && !AppTerminate() )
{
	if( !AppSuspended() ) // We are not in focus!
	{
		// Rotate cube
		if(KeyHit(KEY_SPACE))
		{
			PositionEntity(meshBody, EntityPosition(controller, 1), 1);

			AddBodyForce(meshBody, Vec3(0, 250, 250), 0);
		}

		// This is how we tell if we should be following the body box
		TVec3 vel = GetBodyVelocity(meshBody);
		if(vel.X != 0 || vel.Y != 0 || vel.Z != 0)
		{
			TVec3 pos = EntityPosition(meshBody, 1);
			pos.Y -= .5;
			PositionEntity(controller, pos, 1);
		}
		else
		{
			UpdateController(controller);
		}

		/*if(meshBody != 0)
		{
			TVec3 vel = GetBodyVelocity(meshBody);

			DrawText(10, 10, "Body Velocity %d, %d, %d", vel.X, vel.Y, vel.Z);*/
			/*if(ControllerAirborne(meshBody))
			{
				TVec3 pos = EntityPosition(meshBody, 1);
				pos.Y -= .5;
				PositionEntity(controller, pos, 1);
			}*/
		//}

		// Would only need to do this for the ability. Could stop once the body box is at rest
		//TVec3 pos = EntityPosition(meshBody, 1);
		//pos.Y -= .5;
		//PositionEntity(controller, pos, 1);
		//else
		//	UpdateController(controller);

		// Update timing and world
		UpdateAppTime();
		UpdateWorld(AppSpeed()) ;

		// Render
		SetBuffer(gbuffer);
		RenderWorld();
		SetBuffer(BackBuffer());
		RenderLights(gbuffer);

		vel = GetBodyVelocity(meshBody);
		DrawText(10, 10, "Body Velocity %d, %d, %d", vel.X, vel.Y, vel.Z);

		if(ControllerAirborne(controller) && (vel.X != 0 || vel.Y != 0 || vel.Z != 0))
		{
			DrawText(10, 50, "I am in the air"); 
		}

		// Send to screen
		Flip(0) ;
	}
}

// Done
return Terminate() ;
}

Link to comment
Share on other sites

Yeah. I ran into the same problem, I need to adjust position of the characters exactly each frame but still have them both affect other objects and be affected by other objects. I wasn't able to get a good balance in LE, so I just switched over to using Unity for a bit. Once I get everything worked out there and have a prototype I'll come back and work on porting it to LE.

Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX

ZBrush - Blender

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