Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peculiar lateral thrust calculation #2

Open
Skeletonxf opened this issue Jan 17, 2021 · 0 comments
Open

Peculiar lateral thrust calculation #2

Skeletonxf opened this issue Jan 17, 2021 · 0 comments

Comments

@Skeletonxf
Copy link

Hi

First of all, thanks for making this mod open source. I found a peculiar line while porting the code from new movement physics into my mod.

else if(!vectorMovement) {
    targRot = quaterniond_fromVecToVec(vec3d_front(), dest - obj.position, vec3d_up());
    // Added code to apply a little bit of thrust even when not rotated.
    {
        double dot = targRot.dot(obj.rotation);
        if(dot < 0.999) {
            if(dot < -1.0)
                dot = -1.0;
	}
        else {
            if(dot > 1.0)
                dot = 1.0;
        }

        // dot is now in the range -1 to +1, where 0 is a rightangle between target rotation and current rotation.
        // Therefore, if we take 35% of the acceleration and multiply that by the absolute value of dot
        // we'll achieve the goal of slight off-axis acceleration, scaling up to 35% when it's almost parallel, and then the
        // normal code will take over when rotating is false or vector movement is true, as this entire block is only executed as
        // an else to the standard rotation/accel block.
        double absdot = dot < 0 ? 0-dot : dot; 
        double ratio = absdot * offAxisThrustMultiplier; // 35% thrust scaled down to zero sideways.
        double timeLeft = time;
	do {
            double take = 0;
            obj.acceleration = accToGoal(a, take, dest - obj.position, destVel - obj.velocity) * ratio;
            take = min(timeLeft, max(take, 0.01));
            obj.position += obj.acceleration * (take * take * 0.5);
            obj.velocity += obj.acceleration * take;
            timeLeft -= take;
        } while(timeLeft > 0.0001);
    }
}

this snippet in the Mover component, specifically

obj.acceleration = accToGoal(a, take, dest - obj.position, destVel - obj.velocity) * ratio;

my understanding is accToGoal uses the a argument given to it to determine which way to accelerate, so shouldn't this line be applying the lateral thrust ratio to the a given to it, rather than applying it to the new acceleration accToGoal is computing based on 100% acceleration?

obj.acceleration = accToGoal(a * ratio, take, dest - obj.position, destVel - obj.velocity);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant