tagwolf
Member
REALISTIC THROTTLE RESPONSE (AIRPLANE)
GM Version: 2.2.5
Target Platform: ALL
Download: N/A
Links: https://www.grc.nasa.gov/WWW/K-12/airplane/forces.html
Summary:
This will be part of a series on creating basic flight physics models (if you can call anything involving flight physics "basic").
In particular, this deals with creating a realistic throttle response and could be used in any number of different simulations so just because it's for flight, it's a good technique to learn how to iterate values in this way in general.
TODO:
Tutorial:
Create obj_flight_controller (no sprite) and place it in your room
# Create Event
# Step Event
# Draw Event
GM Version: 2.2.5
Target Platform: ALL
Download: N/A
Links: https://www.grc.nasa.gov/WWW/K-12/airplane/forces.html
Summary:
This will be part of a series on creating basic flight physics models (if you can call anything involving flight physics "basic").
In particular, this deals with creating a realistic throttle response and could be used in any number of different simulations so just because it's for flight, it's a good technique to learn how to iterate values in this way in general.
TODO:
- For use in flight sim, create a thrust value based on engine_speed * engine_power - DONE
- I've added a thrust calculation. It doesn't mean much without drag right now (look for the next series) and drag doesn't mean much without airspeed! We'll get there! - PARTIAL
- Thrust and Drag have been added at a basic level, we still need tweaking, prop to airspeed lag, real-life power and drag values, and actual power curves.
- This tutorial will continue to improve but will only cover thrust and drag
- lift and weight, air density with altitude, along with physics enhancements, will come in later parts.
- I mean... look what we are up against:
Source: https://www.grc.nasa.gov/WWW/K-12/airplane/climb.html
Tutorial:
Create obj_flight_controller (no sprite) and place it in your room
# Create Event
GML:
throttle = 0.0;
throttle_response = 0.5;
engine_speed = 0;
engine_idle_speed = 1700.0;
engine_max_speed = 2600.0;
engine_response = 2.0;
engine_reduction_response = 3.0;
engine_power = 0.2;
thrust = 0.0;
target_airspeed = 0.0;
airspeed_factor = 1.0;
airspeed = 0.0;
drag = 0.0;
drag_coefficient = 0.1;
drag_area = 1.0;
air_density = 1.0;
GML:
if keyboard_check(vk_up) && throttle < 100
{
throttle += throttle_response;
}
if keyboard_check(vk_down) && throttle > 0
{
throttle -= throttle_response;
}
// over-throttle protection
if throttle > 100 { throttle = 100; }
// under-throttle protection
if throttle < 0 { throttle = 0; }
// move engine to idle
if engine_speed < engine_idle_speed { engine_speed = engine_idle_speed; }
// calculate target rpm based on throttle
engine_target_speed = (engine_max_speed - engine_idle_speed) * (throttle / 100) + engine_idle_speed;
// throttle = 0% = target engine speed of 1700
// throttle = 50% = target engine speed of 2150
// throttle = 100% = target engine speed of 2600
if engine_speed < engine_target_speed
{
engine_speed += engine_response;
}
if engine_speed > engine_target_speed
{
engine_speed -= engine_reduction_response;
}
// over-rev protection
if engine_speed > engine_max_speed { engine_speed = engine_max_speed; }
// under-idle protection
if engine_speed < engine_idle_speed { engine_speed = engine_idle_speed; }
// calculate thrust
thrust = (engine_speed - engine_idle_speed) * engine_power;
// calculate drag
drag = drag_coefficient * (air_density * (airspeed * 2) / 2) * drag_area;
// calculate target airspeed
target_airspeed = thrust - drag * airspeed_factor;
// temp airspeed
airspeed = target_airspeed;
GML:
draw_text(10, 10, "throttle = " + string(throttle));
draw_text(10, 30, "throttle_response = " + string(throttle_response));
draw_text(10, 50, "engine_speed = " + string(engine_speed));
draw_text(10, 70, "engine_max_speed = " + string(engine_max_speed));
draw_text(10, 90, "engine_response = " + string(engine_response));
draw_text(10, 110, "thrust = " + string(thrust));
draw_text(10, 130, "drag = " + string(drag));
draw_text(10, 150, "airspeed = " + string(airspeed));
Last edited: