Skip to content

Add random trajectory spread to throwable projectiles #1208

@HashimTheArab

Description

@HashimTheArab

In vanilla, all throwable projectiles (snowballs, eggs, ender pearls, wind charges) have a small random offset applied to their trajectory on each axis using a triangular distribution (random.triangle(0, 0.0172275)). Dragonfly currently fires all throwables in an exact straight line with no spread.

The vanilla algorithm (per the wiki):

  1. Get the unit facing vector of the player (with a per-item pitch offset)
  2. For each axis, add a random value in [-0.0172275, 0.0172275] using a triangular distribution
  3. Scale the result by the item's POWER
    4. Add the player's velocity (Y component unaffected if the player is on ground (java only)

Affected items: Snowball, Egg, EnderPearl, WindCharge, and Bow/Crossbow

This would look like this

const spread = 0.0172275
vel = vel.Add(mgl64.Vec3{
	spread * (rand.Float64() - rand.Float64()),
	spread * (rand.Float64() - rand.Float64()),
	spread * (rand.Float64() - rand.Float64()),
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions