Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Vanilla default missile acceleration, start and max speed

Discussion in 'Programming (In-game)' started by cheerkin, Mar 30, 2018.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. cheerkin Trainee Engineer

    Messages:
    62
    I'm tuning a predicted interception point logic, and have issues with precise missile travel time calculation. Right now I'm using hardcoded value of 195, which works more-a-less well.

    I've checked the sources recently, and found this:

    Code:
    if (ammoDefinition.AmmoType == MyAmmoType.Missile)
    	{
    		//missiles are accelerating, shotSpeed is reached later
    		var mDef = (Sandbox.Definitions.MyMissileAmmoDefinition)ammoDefinition;
    		if (mDef.MissileInitialSpeed == 100f && mDef.MissileAcceleration == 600f && ammoDefinition.DesiredSpeed == 700f)//our missile
    		{//This is very good&fast correction for our missile, but not for some modded exotics with different performance
    			//still does not take parallel component of velocity into account, I know, but its accurate enough
    			shotSpeed = 800f - 238431f / (397.42f + (float)(predictedPosition - Turret.GunBase.GetMuzzleWorldPosition()).Length());
    		}
    		//else {unknown missile, keep shotSpeed without correction}
    	}
    
    This is quite confusing. 700 max speed?
    At 600m the equation above gives us ~560m/s average speed, but it seems very unlikely that a rocket would cover 600m in one second.
    Can anyone clarify this? How do you define speed function of the rockets in your aiming scripts?
     
  2. Sirhamsteralot Trainee Engineer

    Messages:
    28
    afaik missiles are capped at 200m/s
     
  3. Arcturus Senior Engineer

    Messages:
    1,649
    1. Sources found online are out of date, but
    2. that chunk of code is still in use when the game's current code is examined using C# reflection.

    3. Missiles used to be 100 m/s initial, 700 m/s max speed with 600 m/s2 acceleration. This was changed in an update to 200 m/s max speed, causing missile targeting to be messed up. 01.179.0 or earlier.

    4. Also, missiles still have 600 m/s acceleration, causing them to *push* against the 200 m/s speed limit.
    Launched sideways from a ship heading along X at 100 m/s, a missile initially has (x 100, y 100) m/s velocity.
    When it hits the speed limit it is travelling at (x 100, y 173) m/s, which has a vector magnitude of 200 m/s.
    A short time later it will be moving at (x 0, y 200) m/s.
     
    • Informative Informative x 1
  4. cheerkin Trainee Engineer

    Messages:
    62
    Thank you, that's very helpful. I found this via reflection (but probably not the latest libs) and just copied the original source for the sake of readability.

    I guess the same truncation is applied to bodies in the natural gravity environment, right? Where can I find the exact function of how fast the remaining "side" component would be eaten by the normal component?
     
  5. Arcturus Senior Engineer

    Messages:
    1,649
    Physics update steps are 1/60 of an in-game second (not a real life second due to sim speed ratio). This is about 16.7 milliseconds. Say a ship is flying sideways in-atmosphere at its maximum of 100 m/s and has a 10 m/s2 acceleration down towards a planet. In one step it gains 0.1667 m/s downwards velocity, so its total velocity is now 100.0001 m/s. Some vector math required. BUT now the game does the speed limit truncation, keeping the same vector direction, so it becomes 0.1666 m/s downwards and 99.9998 m/s. Some rounding error in there. Seems small, but your course starts to change until you align with the acceleration.

    One of those players who programs in-game guided missiles and stuff once made code to crunch this math so they could drop unguided bombs at the right time from a fast-moving bomber. I forget where I saw that.
     
  6. cheerkin Trainee Engineer

    Messages:
    62
    So I guess for x acceleration it is as simply as
    1. Apply the x velocity delta
    2. Reduce y respecting x^2 + y^2 < 100^2
     
  7. Arcturus Senior Engineer

    Messages:
    1,649
    FTFY.

    If the velocity of a ship was (80, 126.9) which is speed 150, it would scale like:

    Velocity x 100/150 = (53.3, 84.6) which is speed 100.
     
  8. cheerkin Trainee Engineer

    Messages:
    62
    Makes sense. Thank you again!
     
Thread Status:
This last post in this thread was made more than 31 days old.