Skip to content

Commit

Permalink
Improve projectile velocity calculation.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Sep 4, 2013
1 parent ec6e964 commit 372d52a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
Expand Up @@ -147,7 +147,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
aH.debugObj("destination", destination) +
aH.debugObj("height", height) +
aH.debugObj("gravity", gravity) +
(script != null ? aH.debugObj("script", script) : ""));
(script != null ? aH.debugObj("script", script.identify()) : ""));

// Keep a dList of entities that can be called using %shot_entities%
// later in the script queue
Expand Down Expand Up @@ -188,7 +188,9 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept

Position.mount(Conversion.convert(entities));

// Only use the last projectile in the task below
// Get the entity at the bottom of the entity list, because
// only its gravity should be affected and tracked considering
// that the other entities will be mounted on it

final dEntity lastEntity = entities.get(entities.size() - 1);

Expand Down Expand Up @@ -244,7 +246,7 @@ else if (lastVelocity != null) {
}
}

// Stop the task and and run the script if conditions
// Stop the task and run the script if conditions
// are met

if (!flying) {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/net/aufdemrand/denizen/utilities/Velocity.java
Expand Up @@ -7,7 +7,8 @@ public class Velocity {
/**
* Calculates the vector between two locations' vectors
*
* Thanks to SethBling.
* Original code by SethBling, edited to be a bit
* more accurate.
*
* @param from The origin's vector
* @param to The destination's vector
Expand All @@ -31,9 +32,9 @@ public static Vector calculate(Vector from, Vector to, double gravity, double he
double c = -endGain;

double slope = -b / (2 * a) - Math.sqrt(b * b - 4 * a * c) / (2 * a);

// Vertical velocity
double vy = Math.sqrt(maxGain * gravity);
double vy = Math.sqrt(maxGain * (gravity + 0.0013675090252708 * heightGain));

// Horizontal velocity
double vh = vy / slope;
Expand Down
Expand Up @@ -6,13 +6,13 @@ public enum Gravity {
EXPERIENCE_ORB("XPOrb", 0.115),
LEASH_HITCH("LeashKnot", 0.115),
PAINTING("Painting", 0.115),
ARROW("Arrow", 0.115),
SNOWBALL("Snowball", 0.075),
ARROW("Arrow", 0.118),
SNOWBALL("Snowball", 0.076),
FIREBALL("Fireball", 0.115),
SMALL_FIREBALL("SmallFireball", 0.115),
ENDER_PEARL("ThrownEnderpearl", 0.115),
ENDER_SIGNAL("EyeOfEnderSignal", 0.115),
THROWN_EXP_BOTTLE("ThrownExpBottle", 0.115),
THROWN_EXP_BOTTLE("ThrownExpBottle", 0.157),
ITEM_FRAME("ItemFrame", 0.115),
WITHER_SKULL("WitherSkull", 0.115),
PRIMED_TNT("PrimedTnt", 0.115),
Expand Down Expand Up @@ -56,7 +56,7 @@ public enum Gravity {
VILLAGER("Villager", 0.115),
ENDER_CRYSTAL("EnderCrystal", 0.115),
SPLASH_POTION(null, 0.115),
EGG(null, 0.115),
EGG(null, 0.074),
FISHING_HOOK(null, 0.115),
LIGHTNING(null, 0.115),
WEATHER(null, 0.115),
Expand Down

0 comments on commit 372d52a

Please sign in to comment.