# Body Forces on Character Controllers & 2D Constraint

## Recommended Posts

I've come to the understanding that LE2 doesn't support body forces for character controllers. It would be really nice if LE3 supported this (even better if 2 did also!). It's useful for any type of game.

Also, I'm making a platformer a little bit like Trine. It would be nice to limit body and character controller movement to a 2D plane with a single function, like

`RestrainBodyMovement(player1,Vec3(1,1,0));`

Thanks!

Bonus points if

`RestrainBodyMovement(player1,Vec3(.5,2,0));`

makes movement half speed on the X axis, double speed on the Y axis and 0 on the Z axis.

##### Link to post

I think this is a standard thing in Physics engines ? A simple Axis constraint i fact !

It is an example on a 2D platform Unity tutorial unsig an axe constraint, it can happen anything : physic explosion, object rotation around any axe,

the objects can't move on the axe constraint , perhaps you could check it out to be inspired or to see if Newton don't already have that ?

But i agree it can be a usefull feature for making any 2.5D style games playing in a screen plane and using 3D objects like 2.5D platformers , to puzzle games etc ...

##### Link to post

I posted a solution used by games in industry and that works great !

Games like Pandemonium, Klonoa, ViewTifull Joe, Killer Seven etc ....

I re post here the solution i posted in the blog site right bar :

Another idea ? Simply create a Path along your level telling character, NPC , bullets, cars etc ... to follow it forward or backward !

Like Pandemonium PS1 game !

Just make a path for player, NPC etc ... to follow and make them follow it forward or backward without physics.

If you really need physics, perhaps make invisible walls meshes for collision (God of War game solution on PS2 used that type of collision :

invisible meshes created uppon the level on Maya software) !

##### Link to post

Thanks YouGroove. I'm definitely not out of workaround options. Worst case scenario, if the walls around the player don't end up working out, I may simply remove the physics altogether and do them myself, using another library called PMask. It's much more of a pain but it also gives me full control.

But yes, this really should be in the engine, in my opinion.

##### Link to post

For character controllers, it's actually perfectly fine to constrain them yourself by just setting the Z position to 0. It won't hurt anything. I don't like having inconsistency like that, but if you want a solution right now, it will work. Don't do this with regular physics bodies.

##### Link to post

Like via PositionEntity()? I thought calling those commands on bodies causes collision issues?

##### Link to post

Yes, but the character controller isn't really a physics body. It uses my own simple physics, so I can control it completely.

##### Link to post

I've run into horrible issues with the current version and axis restraints, physics bodies in particular.

I either have to create several invisible walls that limit movement, or use a curve algorithm that adjusts the position every frame.

This is a must!

+1

##### Link to post

I will strongly consider this, since 2.5d games will be more common in L3.

You can however use CalcBodyVelocity() to calculate what force you need to apply to keep bodies on a flat plane.

##### Link to post

PositionEntity doesn't seem to work on the character controller. I originally posted a thread here but I thought I'd post my code here as well, in case you have any ideas.

Very simple code. No assets needed. Copy it right into a new project if you'd like.

```#include "engine.h"

#pragma warning(disable:58)

int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd )
{
if(!Initialize()) return 1;

// Set graphics mode
if(!Graphics(640,480))
{
MessageBoxA( 0,"Failed to set graphics mode.","Error",0);
return 1;
}

// Create framework object and set it to a global object so other scripts can access it
TFramework fw = CreateFramework();
if(fw==NULL)
{
MessageBoxA(0,"Failed to initialize engine.","Error",0);
return 1;
}

// Set Lua framework object
SetGlobalObject("fw",fw);

// Set Lua framework variable
BP lua=GetLuaState();
lua_pushobject(lua,fw);
lua_setglobal(lua,"fw");
lua_pop(lua,1);

// Get framework main camera
TCamera camera = GetLayerCamera(GetFrameworkLayer(0));
PositionEntity(camera,Vec3(13,5,-12));
RotateEntity(camera,Vec3(15,0,0));

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

SetWorldGravity(Vec3(0,-80,0));

// PLAYER
TController player=CreateController(1.8,0.4,0.5,45.01);
EntityType(player,1);
SetBodyMass(player,10);
PositionEntity(player,Vec3(0,1,0));

float move=0.0;
float strafe=0.0;

// GROUND
TEntity ground=CreateBodyBox(40,1,1,0);
SetBodyMass(ground,0);
EntityType(ground,2);

Collisions(1,2,true);

DebugPhysics(1);

SetStats(2);

while(!KeyHit(KEY_ESCAPE))
{
TVec3 pos;

move=KeyDown(KEY_RIGHT)-KeyDown(KEY_LEFT);
pos=EntityPosition(player,1);
PositionEntity(camera,Vec3(pos.X,pos.Y+4,-15));

float jump=0.0;
if (KeyHit(KEY_SPACE)) {
if (!ControllerAirborne(player)) {
jump=30.0;
}
}

move*=10;

UpdateController(player,270.0,move,0.0,jump,50);

pos=EntityPosition(player,1);
//		PositionEntity(player,Vec3(pos.X,pos.Y,0),1);

UpdateFramework();
RenderFramework();

DrawText(0,300,"player.Z: %f",pos.Z);

Flip(0);
}

return Terminate();
}
```

With the PositionEntity line commented, the character controller works fine. With it uncommented, it seems to break (the character controller becomes almost entirely non-responsive). But please let me know if I'm doing something wrong.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×

• Pages

• Back
• Store

• #### Support

• Projects
×
• Create New...