Jump to content

Making a body start and stop faster


Rick
 Share

Recommended Posts

I'm using some spectator code that I found around the forum that uses a body sphere to move the camera around. I like this because I want totally free camera movement, but I would prefer more precise movement. Currently the sphere takes awhile to come to a rest. When I let go of the movement key I would prefer it instantly stop. How can I achieve that?

 

       // setup code 
       TBody spectator = CreateBodySphere();
       SetBodyMass(spectator, 50);
       SetBodyGravityMode(spectator, 0);			// disable gravity for this body
       SetBodyDamping(spectator, 500.0);
       EntityType(spectator, 3);
       SetBodyBuoyancyMode(spectator, 1);
       PositionEntity(spectator,Vec3(0,5,-10));
       mx=Curve(MouseX()-GraphicsWidth()/2,mx,5);
       my=Curve(MouseY()-GraphicsHeight()/2,my,5);
       MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2);

// main loop code
       camrotation.X=camrotation.X+my/10.0;
       camrotation.Y=camrotation.Y-mx/10.0;
       RotateEntity(cam,camrotation);

       move=KeyDown(KEY_W)-KeyDown(KEY_S);
       strafe=KeyDown(KEY_D)-KeyDown(KEY_A);
       TVec3 force = Vec3(strafe * 200.0,0,move * 200.0);
       force = TFormVector(force, cam, 0);
       AddBodyForce(spectator, force);

       PositionEntity(cam,EntityPosition(spectator));

Link to comment
Share on other sites

You can add a active break system and adjust the break factor:

	if( (move==0 && strafe==0 && jump==0 && autobrake) || KeyDown() )
{
	TVec3 vel=GetBodyVelocity( pla->body );
	vel.X=-vel.X*2;
	vel.Y=-vel.Y*2;
	vel.Z=-vel.Z*2;
	AddBodyForce( pla->body, vel );
}

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

Don't move the camera by "Forces" ....

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

Link to comment
Share on other sites

Don't move the camera by "Forces" ....

 

To get the physics to work with collisions on bodies (which is something I want) I have to move the bodies by forces don't I? I can't use anything else or it'll break the physics right? That's my understanding of it anyway.

Link to comment
Share on other sites

what exactly are you trying to do?

AMD Bulldozer FX-4 Quad Core 4100 Black Edition

2 x 4GB DDR3 1333Mhz Memory

Gigabyte GeForce GTX 550 Ti OC 1024MB GDDR5

Windows 7 Home 64 bit

 

BlitzMax 1.50 • Lua 5.1 MaxGUI 1.41 • UU3D Pro • MessiahStudio Pro • Silo Pro

3D Coat • ShaderMap Pro • Hexagon 2 • Photoshop, Gimp & Paint.NET

 

LE 2.5/3.4 • Skyline UE4 • CE3 SDK • Unity 5 • Esenthel Engine 2.0

 

Marleys Ghost's YouTube Channel Marleys Ghost's Blog

 

"I used to be alive like you .... then I took an arrow to the head"

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