Hello, I’m stuck on an issue that I want to implement. It’s a trajectory module where you can input variables and it will end up on the end position. But I’m struggling to implement something like this:
I need to find some stuff for this trajectory, like the angle at which it’s thrown, the time taken, the distance, and the y-axis and x-axis needed to travel to the endpoint.
I found a script where it’s a trajectory, some things aren’t changeable, like the theta angle. it relies on duration, depending on the duration, it goes higher.
while true do
task.wait(2)
local position1 = workspace.Position1
local position2 = workspace.Position2
local direction = position2 - position1
local duration = math.log(0.001 + direction.Magnitude * 0.01)
position2 = workspace.Position2 + workspace.Position2.AssemblyLinearVelocity * duration
direction = position2 - position1
local force = direction/duration + Vector3.new(0, game.Workspace.Gravity * duration * 0.5, 0)
end
That being said, how would I go on to make something like this?
Im confused is the issue adding bullet drop? Because if you need to have it drop then just have a loop that reduces the y axis by x amount every x.
I recommend using run service for any physic stuff. Like renderstepped or heartbeat (forgot what’s better for this) and also if your gonna use while loops you can just do while task.wait() and it will do the same thing as it being while true and having a task.wait() anywhere else in the code like below.
Welcome to the world of physics! I would recommend looking in to the UAM equations: Uniformly-Accelerated Motion | Quantities, Equations & Examples - Lesson | Study.com. Your situation takes place in 3D, but the general idea is the same. It looks like you intend on including varying velocities and accelerations however, which can exponentially increase the math(literally, you will have a quartic instead of a quadratic). If you have a change in position, no net velocities, a set inital/launch velocity, and a difference in acceleration, you can use:
d = v0*t + 0.5a*t^2
If you want differing positions, velocities, and accelerations, this will be a much longer discussion. I have spent about a month on this topic, and I have a full module, but it’s quite difficult to use.
I’ll create a new topic in a few days and post my module. I spent a lot of time on Wikipedia coding it, but it is insanely precise. Give me some time, and I’ll post it in community resources, along with a link here.
You can view the forum post here: Trajectory Prediction, but I’m not entirely sure if that is your exact issue. If you could explain in a little more detail the information you have, and the information you need, along with what the end goal is(game you plan on implementing this into), I might be of more assistance.
Thank you for this module! Because of the lack of posts on this topic, I think I eventually dropped the idea, what I wanted to do was make something like this:
Input some values, and make the ball go in a curve, whilst predicting where it would land.
I believe your module covers all of that, but is there any way to visualize the trajectory like in the image above?
I would write something that creates a point at various t values. If you look near the end of my module, you can see where it shows the bullet will be based on a t value. I believe you should be able to write it yourself, but u can help if needed. Give a function an initial position, an aim velocity(multiplied by the speed), and the acceleration. Have that function create a little sphere at each point, and use a for loop and regular increments calling that function based on the time value. This won’t include any raycasting, so it won’t have collision detection, but you could end once the position is below a certain value. Make sure you clear out all the parts, or use a PartCache to avoid needing to destroy and replace them.