mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 11:36:43 +01:00
More work on the new flight mechanics
This commit is contained in:
parent
bff01ff787
commit
71ea2f646a
2 changed files with 79 additions and 8 deletions
|
@ -0,0 +1,50 @@
|
|||
package com.minelittlepony.unicopia.entity.player;
|
||||
|
||||
import com.minelittlepony.unicopia.util.MutableVector;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public class AeronauticalPlayerPhysics extends PlayerPhysics {
|
||||
|
||||
private final Aeronautics auronautics = new Aeronautics();
|
||||
|
||||
private double gravity;
|
||||
|
||||
private int thrustCountdown;
|
||||
|
||||
public AeronauticalPlayerPhysics(Pony pony) {
|
||||
super(pony);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double calcGravity(double worldConstant) {
|
||||
return gravity = super.calcGravity(worldConstant);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void moveFlying(Entity player, MutableVector velocity) {
|
||||
|
||||
PlayerEntity ply = (PlayerEntity)player;
|
||||
|
||||
auronautics.pitchAngle = 0;
|
||||
auronautics.rollAngle = 0;
|
||||
|
||||
float yaw = player.getYaw(1);
|
||||
|
||||
Vec3d motion = auronautics.calcGravitationalAccelleration(gravity);
|
||||
|
||||
if (ply.forwardSpeed != 0 && thrustCountdown-- <= 0) {
|
||||
thrustCountdown = 20;
|
||||
player.playSound(getWingSound(), 0.4F, 1);
|
||||
motion = motion.add(auronautics.calcThrustVelocity(-100));
|
||||
}
|
||||
|
||||
motion = motion.rotateY(yaw).add(velocity.toImmutable()).multiply(1 - auronautics.getDrag());
|
||||
|
||||
velocity.x = motion.x;
|
||||
velocity.y = motion.y;
|
||||
velocity.z = motion.z;
|
||||
}
|
||||
}
|
|
@ -14,20 +14,41 @@ public class Aeronautics {
|
|||
* Gets the normalized direction vector
|
||||
*/
|
||||
private Vec3d getMomentVector() {
|
||||
Vec3d bankVector = new Vec3d(0, Math.sin(rollAngle), Math.cos(rollAngle));
|
||||
// sine(angle) = y/h
|
||||
// cos(angle) = x/h
|
||||
|
||||
Vec3d climbVector = new Vec3d(Math.cos(pitchAngle), Math.sin(pitchAngle), 0);
|
||||
Vec3d bankVector = new Vec3d(0, Math.sin(rollAngle), Math.cos(rollAngle));
|
||||
|
||||
return bankVector.add(climbVector).normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the normalized perpendicular vector.
|
||||
*/
|
||||
private Vec3d getNormal() {
|
||||
// sine(angle) = y/h
|
||||
// cos(angle) = x/h
|
||||
|
||||
Vec3d climbVector = new Vec3d(Math.cos(pitchAngle), Math.sin(pitchAngle), 0);
|
||||
Vec3d bankVector = new Vec3d(0, Math.sin(rollAngle), Math.cos(rollAngle));
|
||||
|
||||
return bankVector.crossProduct(climbVector).normalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the acceleration vector due to gravity in the direction of
|
||||
* the incline described by the roll and pitch components.
|
||||
* Returns the acceleration vector due to gravity
|
||||
* parallel to the slope of the incline described
|
||||
* by the roll and pitch components.
|
||||
*
|
||||
* @param gravity The global gravitation constant C
|
||||
*/
|
||||
public Vec3d calcGravitationalAccelleration(double gravity) {
|
||||
return getMomentVector().multiply(-gravity);
|
||||
return getMomentVector().multiply(
|
||||
-gravity * Math.signum(pitchAngle),
|
||||
-gravity,
|
||||
-gravity * Math.signum(rollAngle)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -37,10 +58,10 @@ public class Aeronautics {
|
|||
* @param forwards The forwards thrust speed
|
||||
* @param velocity The current motion vector
|
||||
*/
|
||||
public Vec3d calcThrustVelocity(double forwards, Vec3d velocity) {
|
||||
velocity = velocity.normalize().multiply(forwards);
|
||||
|
||||
return getMomentVector().multiply(velocity.x, velocity.y, 0).multiply(getDrag());
|
||||
public Vec3d calcThrustVelocity(double forwards) {
|
||||
return getNormal().add(getMomentVector())
|
||||
.normalize()
|
||||
.multiply(forwards * (1 - getDrag()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue