Minecart system overhaul
#10
I think I will try to implement the friction the way i read it from the decompiled code. I'll then set up some tests and check wether it really behaves like it does in vanilla or not. Changing the friction equation afterward should be easy.

I've written some more-or-less-pseudocode how I'd like to implement this. Notice that I'd get rid of HandlePoweredRailPhysics, HandleDetectorRailPhysics and HandleActivatorRailPhysics in favour of only one function: HandleRailEffect. HandleRailEffect is called by HandleRailPhysics. HandleRailPhysics is called independent which rail type it is on.

Vector3d GetExitPoint(RailType, Speed);
// Gets the coordinates at which the cart will exit this block. Needs speed to know the direction

Vector3d GetMovingDirection(RailType, Speed);
// Returns a normalized vector. Needs speed to know the direction

void HandleRailEffect(RailType, Speed);
// Handle the effects of special rails (also includes inclined rails!)


void HandleRailPhysics()
{

      CurrentBlock = GetBlock(GetPos());
      DistanceToTravel = GetSpeed().Length();

      while (DistanceToTravel > 0)
      {

            HandleRailEffect (CurrentBlock, Speed);

            ExitDirection = GetExitPoint() - GetPos();

            if (DistanceToTravel < ExitDirection)
            // Cart halts in this block
            {
                  AddPos(GetMovingDirection() * DistanceToTravel);
                  DistanceToTravel = 0;
            }
            else
            // Cart will travel further blocks
            {
                  DistanceToTravel -= (GetExitPosition() - GetPos()).Length();
                  SetPos(GetExitPosition());
                  CurrentBlock = GetBlock(GetExitPosition() + GetMovingDirection(CurrentBlock, GetSpeed()) * 0.1);
                  // GetMovingDirection(CurrentBlock, GetSpeed()) * 0.1 is to be sure we land in the next block
                  SetSpeed(GetMovingDirection(CurrentBlock, Speed) * Speed.Length());
            }

      }

      // Handle friction, in whatever way we decide to
      Speed *= FRICTION_CONSTANT;
}

This doesn't handle yet if the rails suddenly stop. Another problem is that rail effects don't change the DistanceToTravel, but I wonder wether this is really an issue.
Reply
Thanks given by:


Messages In This Thread
Minecart system overhaul - by ChriPiv - 08-18-2014, 02:42 AM
RE: Minecart system overhaul - by xoft - 08-18-2014, 06:27 AM
RE: Minecart system overhaul - by ChriPiv - 08-18-2014, 08:11 AM
RE: Minecart system overhaul - by ChriPiv - 08-18-2014, 11:42 PM
RE: Minecart system overhaul - by tigerw - 08-19-2014, 01:44 AM
RE: Minecart system overhaul - by NiLSPACE - 08-19-2014, 02:29 AM
RE: Minecart system overhaul - by xoft - 08-19-2014, 06:40 AM
RE: Minecart system overhaul - by tigerw - 08-20-2014, 06:58 AM
RE: Minecart system overhaul - by ChriPiv - 08-19-2014, 10:57 PM
RE: Minecart system overhaul - by tigerw - 08-19-2014, 11:59 PM
RE: Minecart system overhaul - by ChriPiv - 08-20-2014, 12:39 AM
RE: Minecart system overhaul - by ChriPiv - 08-20-2014, 10:34 PM
RE: Minecart system overhaul - by NiLSPACE - 08-20-2014, 11:13 PM



Users browsing this thread: 2 Guest(s)