#Projectile Angle Calculation

1 messages · Page 1 of 1 (latest)

rustic scaffold
#

Idk what the code Null gave do, but I can help you write one

#

And yes first calculate the time

late karma
#

Thanks

#

But time in air x and y need t in the equation

rustic scaffold
#

But actually watching the video time is going to be removed out

#

You can just get the equation from end of the video

late karma
#

Is it this?

rustic scaffold
#

theta = 0.5f * asin((gravity * distance) / pow(initial_vel, 2));

rustic scaffold
#

g is gravity and v0 is initial velocity

#

Btw this assumes that start Y and destination Y is the same

late karma
#

Is this right?

float g = Vector3.Distance(Physics.gravity, Vector3.zero);
float theta = .5f * Mathf.Asin((g * range) / Mathf.Pow(exitVelocity, 2) * Mathf.Deg2Rad );
rustic scaffold
#

Same thing but still lol

rustic scaffold
late karma
rustic scaffold
#

You need to do it later

late karma
#

Later?

#

So thats not the whole calculation?

#

Hello?

#

I think it works now, but I'm not sure

rustic scaffold
rustic scaffold
rustic scaffold
late karma
#
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?

late karma
#

I placed a target 500m away at the same height as gun and it was a bullseye!
Even when switching ammo types

rustic scaffold
#

Nice, just make sure the value in Asin is -1 ~ 1 range

late karma
#

It's around 0.01 - 0.001 or something

#

Depends on the range

#
THETA: 0.001471501
RANGE: 150
rustic scaffold
#

Anyways if it works well it's good lol

#

I guess your velocity is pretty fast

late karma
#

Yeah 1000m/s

rustic scaffold
#

Oh okay that makes sense... lol

late karma
#

haha

#

Thank you so much! You have helped my project a ton!

rustic scaffold
#

Your tank project I remember 🙂

late karma
#

Ohh, you remember!

rustic scaffold
#

Yup I'd bet it's evolving well

late karma
#

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?

rustic scaffold
#

What momentum are you calculating?

late karma
#

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

rustic scaffold
#

Oh alright so how long does it goes forward if there is no input?

#

From current velocity

late karma
#

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.

rustic scaffold
#

Sure and it's not using rigidbody I guess?

late karma
#

It has a rigidbody, but the movement is based on translating the position.

rustic scaffold
#

Alright and does it calculate friction with ground etc

late karma
#

Could use velocity as well probably should tho

rustic scaffold
#

and you'd calculate this over time is it?

#

Not one frame thing?

late karma
#

Yep, over multiple frames. I'm not sure which approach would be the best.

rustic scaffold
#

But if you want to do with physics material it's gonna be little harder (maybe better to set rigidbody velocity in that case)

late karma
#

No, thanks. I haven't touched those yet

#

velocity *= (1 - Time.deltaTime * drag);

rustic scaffold
#

Basically that's what Unity is doing yes

late karma
#

That doesn't work at all for me

#

maybe my variables are wrong

rustic scaffold
#

What value are you using?

late karma
#

.1 km/h drag

#

Got my vehicle going at mach 6 somehow 🤣 ✈️

rustic scaffold
#

Drag is pretty much of ratio

#

In that equation it should be in 0~1 range

late karma
#

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

rustic scaffold
#

How much value is slopeLoss?

late karma
#

-1 going up slope and 0.75 going down

Those are maxes btw.
They are calculated between 0-max using a slopeRatio

rustic scaffold
late karma
#

speed is the current speed
newVelocity is the new speed transmitted by the gear box

I should probably be called newSpeed.

late karma
rustic scaffold
#
// 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 🤔

late karma
#

Thanks you for your time. I have to go now. I'll catch you later on this thread.

rustic scaffold
late karma
#

@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

rustic scaffold
#

I think it should be relative to your marching direction, tho