I'm sorry if this is considered spamming, but my question hadn't received any more views in about two days and I haven't figured out how to bump a question. Anyway, my problem:
I decided I wanted to do something with the ballistic trajectory equation but I have encounterd the problem that I can't figure out how to move a brick at the same velocity every time but have the angle of the part's trajectory change, or vise versa. I don't want the projectile to follow the player's cursor so I can't just take some gun script and modify (that I have found). I would appreciate any advice anyone can give me on the subject - LightArceus
I was writing a complete answer when I got stuck.
My conclusion: You can't do this. Why? It requires excessive math and even equation solvers like Wolfram Alpha can't do it. I even tried a method which is "almost correct" and even that didn't work due to excessive math.
Well, my approach was this. We want to keep a certain speed constant. That means the distance the bullet travels per second needs to be the same all time. We have a function called y
which gives us the height on a given x
. This x
is the distance (magnitude) from the starting point.
Let's say we already travelled something with our bullet and we are at a distance called d
. We now are 1/60 (1 frame) further and we want to calculate our new function. This is not speed / 60 + d
, because that means our horizontal speed is equal, which can't be true if our angle also changes. That means we need to get the new x (we call this e
) in which the total distance the bullet has travelled is speed * 1/60. We call this dist
.
We can get the length between two points via the integral calculus of:
math.sqrt(1 + (derive(y)^2)
Even for simple functions this is almost impossible to derive. For a sample function -x^2 + 8x Wolfram Alpha returns THIS as integral:
1/4 (2 (-4+x) sqrt(65-32 x+4 x^2)+sinh^(-1)(2 (-4+x)))
Well, at least it is an integral so we can work with that. The problem gets here, now. We call above function the arclen
function. Integral math says that:
arclen(e) - arclen(d) = dist
So, if we want to get "e", we need to do:
arclen(e) = dist + arclen(d)
We can solve the stuff on the right. However, there is NO WAY for us to get an "inverse function" so we can get e of arclen. Trying to retrieve the function from Wolfram Alpha also gives no results. Conclusion: we have no way to find e. I think the function I provided (without trigonometry) already proves that this is extremely hard. You could try to create a brute forcer to solve this, but this will require too much CPU - you can't use your game for anything else besides some plotting of a bullet.
I hope you understood this a little bit. If the integral or derivation definitions confuse you, read some articles on them. Also "arc length" is a cool article to read on.
Locked by TheMyrco
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?