mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-02 03:46:43 +01:00
Start of the flight rewrite
This commit is contained in:
parent
76f7625bb7
commit
85df9737e7
2 changed files with 73 additions and 18 deletions
|
@ -0,0 +1,52 @@
|
||||||
|
package com.minelittlepony.unicopia.entity.player;
|
||||||
|
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
// X - forward
|
||||||
|
// Y - vertical
|
||||||
|
// Z - sideways
|
||||||
|
public class Aeronautics {
|
||||||
|
|
||||||
|
public double rollAngle;
|
||||||
|
public double pitchAngle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the normalized direction vector
|
||||||
|
*/
|
||||||
|
private Vec3d getMomentVector() {
|
||||||
|
Vec3d bankVector = new Vec3d(0, Math.sin(rollAngle), Math.cos(rollAngle));
|
||||||
|
Vec3d climbVector = new Vec3d(Math.cos(pitchAngle), Math.sin(pitchAngle), 0);
|
||||||
|
|
||||||
|
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.
|
||||||
|
*
|
||||||
|
* @param gravity The global gravitation constant C
|
||||||
|
*/
|
||||||
|
public Vec3d calcGravitationalAccelleration(double gravity) {
|
||||||
|
return getMomentVector().multiply(-gravity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the added thrust vector for the given forwards motion
|
||||||
|
* and velocity projected against the direction of incline.
|
||||||
|
*
|
||||||
|
* @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());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The drag due to air resistance.
|
||||||
|
*/
|
||||||
|
public double getDrag() {
|
||||||
|
return 0.0078; // magic number until I figure out what tf I'm doing
|
||||||
|
}
|
||||||
|
}
|
|
@ -147,22 +147,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRainbooming || (entity.isSneaking() && isRainboom())) {
|
if (isRainbooming || (entity.isSneaking() && isRainboom())) {
|
||||||
float forward = 0.5F * flightExperience / MAXIMUM_FLIGHT_EXPERIENCE;
|
performRainboom(entity, velocity);
|
||||||
|
|
||||||
velocity.x += - forward * MathHelper.sin(entity.yaw * 0.017453292F);
|
|
||||||
velocity.z += forward * MathHelper.cos(entity.yaw * 0.017453292F);
|
|
||||||
velocity.y += forward * MathHelper.sin(entity.pitch * 0.017453292F);
|
|
||||||
|
|
||||||
if (!isRainbooming || entity.world.random.nextInt(5) == 0) {
|
|
||||||
entity.playSound(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flightExperience > 0) {
|
|
||||||
flightExperience -= 13;
|
|
||||||
isRainbooming = true;
|
|
||||||
} else {
|
|
||||||
isRainbooming = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,6 +192,25 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP;
|
return pony.getSpecies() == Race.CHANGELING ? USounds.CHANGELING_BUZZ : USounds.WING_FLAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void performRainboom(Entity entity, MutableVector velocity) {
|
||||||
|
float forward = 0.5F * flightExperience / MAXIMUM_FLIGHT_EXPERIENCE;
|
||||||
|
|
||||||
|
velocity.x += - forward * MathHelper.sin(entity.yaw * 0.017453292F);
|
||||||
|
velocity.z += forward * MathHelper.cos(entity.yaw * 0.017453292F);
|
||||||
|
velocity.y += forward * MathHelper.sin(entity.pitch * 0.017453292F);
|
||||||
|
|
||||||
|
if (!isRainbooming || entity.world.random.nextInt(5) == 0) {
|
||||||
|
entity.playSound(SoundEvents.ENTITY_LIGHTNING_BOLT_THUNDER, 1, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flightExperience > 0) {
|
||||||
|
flightExperience -= 13;
|
||||||
|
isRainbooming = true;
|
||||||
|
} else {
|
||||||
|
isRainbooming = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected void moveFlying(Entity player, MutableVector velocity) {
|
protected void moveFlying(Entity player, MutableVector velocity) {
|
||||||
|
|
||||||
float forward = 0.000015F * flightExperience * (float)Math.sqrt(getHorizontalMotion(player));
|
float forward = 0.000015F * flightExperience * (float)Math.sqrt(getHorizontalMotion(player));
|
||||||
|
@ -260,8 +264,7 @@ public class PlayerPhysics extends EntityPhysics<Pony> implements Tickable, Moti
|
||||||
double motionX = e.getX() - lastTickPosX;
|
double motionX = e.getX() - lastTickPosX;
|
||||||
double motionZ = e.getZ() - lastTickPosZ;
|
double motionZ = e.getZ() - lastTickPosZ;
|
||||||
|
|
||||||
return (motionX * motionX)
|
return (motionX * motionX) + (motionZ * motionZ);
|
||||||
+ (motionZ * motionZ);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected SoundEvent getFallSound(int distance) {
|
protected SoundEvent getFallSound(int distance) {
|
||||||
|
|
Loading…
Reference in a new issue