Jump to content

Rotating character & gravity


smashthewindow
 Share

Recommended Posts

Watching this video just gave me a great idea I want to prototype:

 

I was thinking if it was possible to change the orientation of the character entity in Leadwerks.

Another solution is to just change the orientation of everything else other than the player, but I want to consider all my options before doing something stupid.

 

Any help on this?

Blog & Portfolio

 

Current project: moon.chase.star

Link to comment
Share on other sites

Like I have said always, use a pivot to mark the gravity center, and don't use Newton's own gravity at all, it just doesn't work (especially with airplanes and composed multi-part bodies you will see that it just goes nuts). When you have the pivot gravity positioned, make a loop which adds forces to all objects towards the gravity center. That way you can also change the direction of gravity in any direction you want by just moving the gravity pivot.

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

Like I have said always, use a pivot to mark the gravity center, and don't use Newton's own gravity at all, it just doesn't work (especially with airplanes and composed multi-part bodies you will see that it just goes nuts). When you have the pivot gravity positioned, make a loop which adds forces to all objects towards the gravity center. That way you can also change the direction of gravity in any direction you want by just moving the gravity pivot.

 

I have no problem with the Newton's gravity, I'm not making an flight simulation game.

I'm asking whether the controller entity is rotatable.

Blog & Portfolio

 

Current project: moon.chase.star

Link to comment
Share on other sites

don't use Newton's own gravity at all, it just doesn't work (especially with airplanes and composed multi-part bodies you will see that it just goes nuts).

 

There is no default gravity in Newton. Real Newton that is, Likewise, it's also possible to adjust the mass matrix, which I assume would make gravity work correctly for a plane.

void ApplyGravity(const NewtonBody * body, const Entity * ent)
{
   float * NewForce = (float*) malloc(3 * sizeof(float));
   NewForce[0] = 0.0f;
   NewForce[1] = GRAVITY_FORCE * ent->GetGravityMultiplier();
   NewForce[2] = 0.0f;
   NewtonBodyAddForce(body,NewForce);
   free(NewForce);
}
//callback signature provided by Newton. Most of this code is just copied straight from the tutorial... because it works.
void ApplyForceOnlyCallback (const NewtonBody * body, dFloat timestep, int threadIndex)
{
   Entity * ent = (Entity *) NewtonBodyGetUserData(body);
   dFloat Ixx, Iyy, Izz, mass;
   NewtonBodyGetMassMatrix (body, &mass, &Ixx, &Iyy, &Izz);
   TVec3 ForceToAdd = ent->GetForce();
   TVec3 InternalForce = ent->GetSelfForce();
   TVec3 CombinedForce = GetCombinedForce(ForceToAdd,InternalForce);
   ApplyForce(body,ent,CombinedForce);
   if(ent->GravityEnabled())
   {
       ApplyGravity(body,ent);
   }
   ent->ClearForces();
}

 

Of course, I never touch the mass matrix because it works fine for me, and messing about with things I don't know could, well, cause planes to fall out of the sky... But really, it should just be a case of modifying Ixx, Iyy and Izz. Don't ask what to though, because I don't know...

LE Version: 2.50 (Eventually)

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