#Projectile Angle Calculation
1 messages · Page 1 of 1 (latest)
Idk what the code Null gave do, but I can help you write one
And yes first calculate the time
But actually watching the video time is going to be removed out
You can just get the equation from end of the video
Is it this?
theta = 0.5f * asin((gravity * distance) / pow(initial_vel, 2));
x would be distance on XZ plane
g is gravity and v0 is initial velocity
Btw this assumes that start Y and destination Y is the same
Is this right?
float g = Vector3.Distance(Physics.gravity, Vector3.zero);
float theta = .5f * Mathf.Asin((g * range) / Mathf.Pow(exitVelocity, 2) * Mathf.Deg2Rad );
That's fine
Just use -Physics.gravity.y for g
Same thing but still lol
And Deg2Rad is not needed there
Are you sure?
Later?
So thats not the whole calculation?
Hello?
I think it works now, but I'm not sure
I'm back
That is whole calculation but result theta is radian so you should multiply Rad2Deg if you are going to use with Euler angle
But you don't need that Deg2Rad in Asin because it's not angle in that parameter
void CalculateLift()
{
float g = -Physics.gravity.y;
float theta = .5f * Mathf.Asin((g * range) / Mathf.Pow(exitVelocity, 2));
lift = theta * Mathf.Rad2Deg;
}
Does this seem right?
Okay let's try that
I think it's spot on!
I placed a target 500m away at the same height as gun and it was a bullseye!
Even when switching ammo types
Nice, just make sure the value in Asin is -1 ~ 1 range
It's around 0.01 - 0.001 or something
Depends on the range
THETA: 0.001471501
RANGE: 150
Is it? What are you logging XP
Anyways if it works well it's good lol
I guess your velocity is pretty fast
Yeah 1000m/s
Oh okay that makes sense... lol
Your tank project I remember 🙂
Ohh, you remember!
Yup I'd bet it's evolving well
Still doing the basics, but there are so many new features.
If you would like to help just a tiny bit more. Could you help me with calculating momentum?
What momentum are you calculating?
linear momentum?
¯_(ツ)_/¯
I want to calculate when a tank is in neutral. How much does it move forwards based on it's velocity.
Could be as simple as velocity - drag I guess
Oh alright so how long does it goes forward if there is no input?
From current velocity
Well, okay when the vehicle changes gears the maximum velocity is calculated by the gear ratio.
So that the tank would not slowdown to literally zero when the gear is neutral I would like to get the magnitude of new velocity - current velocity and lerp that with drag.
Sure and it's not using rigidbody I guess?
It has a rigidbody, but the movement is based on translating the position.
Alright and does it calculate friction with ground etc
Could use velocity as well probably should tho
Yep, over multiple frames. I'm not sure which approach would be the best.
https://answers.unity.com/questions/652010/how-drag-is-calculated-by-unity-engine.html
So if you just want to mimic Unity drag
But if you want to do with physics material it's gonna be little harder (maybe better to set rigidbody velocity in that case)
Basically that's what Unity is doing yes
What value are you using?
Lol huh
Drag is pretty much of ratio
In that equation it should be in 0~1 range
slopeLoss is the amount you gain or lose going up or down slope
momentum = speed - newVelocity;
drag = drag + slopeLoss;
momentum *= 1 - Time.deltaTime * drag;
speed = momentum;
This causes the speed to go up to >1456 km/h
Lol. Okay slope is more of force than a drag
How much value is slopeLoss?
-1 going up slope and 0.75 going down
Those are maxes btw.
They are calculated between 0-max using a slopeRatio
Hmm. and what is speed and newVelocity ?
speed is the current speed
newVelocity is the new speed transmitted by the gear box
I should probably be called newSpeed.
So speed could be 8.6km/h and newVelocity could be 0
Hmm let me see I don't think you need to calc momentum part
// after applying newSpeed
drag = drag - slopeLoss;
speed *= 1 - Time.deltaTime * drag;
What happen if you just do this? Can you log drag and speed?
Actually higher drag means slower
So it should be substraction 🤔
That fixed the direction the bug happens in.
Thanks you for your time. I have to go now. I'll catch you later on this thread.
Alright have a good rest 🙂
@rustic scaffold
Hello, I am back managed to get the drag working properly, but I'm struggling with slopeLoss
This is what I have right now!
momentum = speed - newSpeed;
momentum += momentum * (-SpeedDirection() * slopeLoss);
momentum *= 1 - Time.deltaTime * drag;
speed = newSpeed + momentum;
float lSpeed = speed * Time.deltaTime;
vehicle.transform.Translate(-forward * (lSpeed / 3.6f), Space.World);
SpeedDirection is just speed > 0 ? 1 : -1
Oh okay what is problem with slopeLoss?
I think it should be relative to your marching direction, tho