#How to track arrow position in minecraft for graphing as quadratic function (without drag)?

1 messages · Page 1 of 1 (latest)

pale turtle
#

not really, but i assume its quite counterintuitive. I guess the easiest way to do it would be to just run the "tracker" on repeat through the whole motion.. not really sure how to do that tho

hearty igloo
#

nah it's not counterintuitive dw

#

tl;dr is

#

thing happens in game (someone shoots a bow) -> server fires event (ProjectileLaunchEvent) -> anything set up to listen for ProjectileLaunchEvent runs the relevant code in an event handler

#

it's like if you fire a gun in a suburban area the police show up

pale turtle
#

xD

#

that makes sense

hearty igloo
#

are you trying to get the real trajectory of the arrow or just convert its launch velocity and angle to an equation?

pale turtle
#

i mean it should be the same

#

bc i have eliminated drag

hearty igloo
#

er, by real i mean

#

if it hits a block midway, though that wouldn't fundamentally change the equation that maps its position

pale turtle
#

the issue is i need all (at least the max and zero points) to be able to graph it as cuadratic

hearty igloo
#

if you're only trying to do the latter, then you don't need to track its position at all

pale turtle
#

id be doing it on a superflat anyways

hearty igloo
#

aye

pale turtle
#

its for a math project

hearty igloo
#

okay that clears things up lmao

#

uh

#

thinking

#

so basically you need to have the equation in X/Y/Z

pale turtle
#

yeah

hearty igloo
#

you can decompose it to a linear system

pale turtle
#

id do only x and y or z and y

hearty igloo
#

since all 3 components are independent of one another, I mean

pale turtle
#

shooting the arrow as if it was a 2d plane as to9 not overcomplicate

#

(straight liine not diagonal within the x/z axis)

hearty igloo
#

Since drag doesn't matter, your X and Z won't really be all that important here

pale turtle
#

wdym

hearty igloo
#

like

#

Sorry I should clarify - your X and Z velocities will remain constant, so you really only need to worry about your Y velocity

#

since gravity

pale turtle
#

oh yes

#

yes

#

honestly velocity isnt my priority anyways

hearty igloo
#

tl;dr you can do this without needing to track the arrow, i'd argue trying to generate a best fit parabola for a set of points would actually be harder lol

pale turtle
#

bc im just graphing the position\

hearty igloo
#

especially with a low tickrate

pale turtle
#

hmm

hearty igloo
#

well, you can do two things

pale turtle
#

fair poinmt

hearty igloo
#
  1. obtain parameterized launch velocity in terms of time t with respect to x/y/z (i phrased this badly)
  2. use a timer to find the real time in flight for any given arrow
#

You actually don't even have to do that much trig here, velocity is stored as a 3d vector on entities so you don't even have to worry about converting the direction vector

pale turtle
#

yes

hearty igloo
#

...that wouldn't be that hard either, come to think of it LOL i think this is entirely trig-agnostic since rotation/etc. is handled already

pale turtle
#

yeah true

hearty igloo
#

i'm p sure velocity is per tick

#

and instantaneous in a given tick

pale turtle
#

yes i think it is

#

again i think its even simpler given that i only need the arrow's position

hearty igloo
#

what you can honestly do is uh

#

run that timer, right

pale turtle
#

yeah

hearty igloo
#

and just feed the time into the equation you have

#

so like if the arrow starts out with a velocity of 10, 10, 10 and is in flight for 20 ticks (1 second)

pale turtle
#

i see what you mean

hearty igloo
#

you'd just do 10 * 20 for both x/z

#

and then for y you'd want to factor in acceleration, which is just 1m/t^2

pale turtle
#

however i dont have an equation yet

#

for the parabola

#

id probably get that from the actual position

hearty igloo
#

well the launch position can tell you everything you need to know

pale turtle
#

true

hearty igloo
#

since that'll tell you what the x/y/z offsets are for one point on the parabola

#

my main concern with tracking its position is gonna be

#

minecraft servers run at 20 ticks per second

#

it's very likely you'll miss the actual maximum of the parabola

pale turtle
#

ohh

#

yeah youre right

hearty igloo
#

like it'd be simpler to track the arrow's position, sure

#

but like for an arrow where you launch it at a relatively gentle angle, it'll pass the maximum at considerable speed

#

this may help you

#

this is like, physics 101

#

kinematics

pale turtle
#

ye ye im in physics HL

hearty igloo
#

vf = final velocity
vi = initial velocity
delta x = change in position on that axis
a = acceleration

pale turtle
#

however

#

if the arrow only moves in each tick, wouldnt it reach the maximum during a tick?

hearty igloo
#

depends on how the server handles things

#

see

#

the server only updates during a tick

#

a good way to showcase what i'm talking about is uh

#

make an arrow tracker and have it just spawn a particle at the arrow's location every tick

#

you'll see how jank it is

#

but you as the player will see the arrow moving smoothly

#

that's because the game interpolates the arrow's location in the render loop

pale turtle
#

true

hearty igloo
#

otherwise you'd have every arrow moving at 20 fps

#

it'd look like shit

#

not just arrows -every entity

pale turtle
#

yeah i see what you mean

#

so ig its more convenient to go for the velocity approach?

#

as the slope in the quadratic function x over y is going to be v anyways

hearty igloo
#

quadratics don't have a slope, wym

pale turtle
#

i mean

hearty igloo
#

they have tangents

pale turtle
#

like slope at a specific given point

hearty igloo
#

yeah

#

okay you meant those

pale turtle
#

thats what i menat

hearty igloo
#

wait what level of maths is this

pale turtle
#

yes

#

basic

hearty igloo
#

okay so there's no calculus involved here

pale turtle
#

nono

hearty igloo
#

was gonna say if you wanted the arrow's velocity at any given point, velocity is a derivative of position and you could just write something really basic to derive it for the y component but that's outside the scope of this project

pale turtle
#

yeah

hearty igloo
#

so yeah for the core of what you're doing here

pale turtle
#

however for that youd still need the position no?

hearty igloo
#

nah

#

not the exact position

hearty igloo
pale turtle
#

i know how the speed is going to change given mcs gravity

#

assuming it is vertical speed not horizontal

#

use that and initial position to get the position at time t

#

then i can probably js graph x/t

pale turtle
#

anyways, thank you very much for the help. I'll let you know how it goes. Cya!

#

How to track arrow position in minecraft for graphing as quadratic function (without drag)?

hearty igloo
#
public class Trajectory {
  private float vx, vy, vz;
  static final float GRAVITY = -1.0f; // not where i'd put this, but for the sake of example
  public Trajectory(float vx, float vy, float vz) {
    this.vx = vx;
    this.vy = vy;
    this.vz = vz;
  }

  // returns the arrow's change in position t ticks after launch
  public Vector evaluate(float t) {
    // very simple since you don't have anything acting on vx/vz
    float dx = vx * t;
    float dz = vz * t;

    float dy = vy * t + 0.5f * GRAVITY * t * t;
    return new Vector(dx, dy, dz);
  }
}```
#

something like that

#

sorry i was afk

hearty igloo
pale turtle
#

Ok

pale turtle
#

I tried using eclipse with a code by chatgpt and just couldnt get it to work

#

Apparently eclipse wasnt recognising my spigot 1.17 jar file so it kept showing errors

#

I js need a way to implement it in mc

hearty igloo
#

how new to programming are you?

hearty igloo
#

chatgpt is shit

#

you will not learn by using it

pale turtle
#

Lol good point

#

Mostly was a last resort

pale turtle
#

😭

#

How could i add the projectilelaunchevent detection to the game (just to get that initial position then its all math) to run it on a server?

hearty igloo
#

very bare bones tutorial

#

all you need

#

incidentally