Topic: basic flight simulator
Hi
I'm trying to implement a (basic) flight simulator. I took a look at the fly demo scene and the fly_between_airport scene. I'm still trying to find out the best way to go with it.
Right now i'm trying to adapt the "followGameObject" script, which looks promising to achieve what i want. I'm adding to this script the same logic used in the "airRoute" script in flight between airport scene:
So the idea is basically to adapt the map zoom level to the aircraft altitude. Also to keep a feeling of being "in the air" i don't want the aircraft to be sitting on a map that change it's zoom. So what i have done is :
-> if the aircraft altitude i less than a 100 meters, the map zoom level does'nt change and the aircraft will just "fly" at it's real altitude above the map mesh. When it reach an altitude > 100m, the map stay at a y distance of 100 meters under the aircraft (to prevent loosing sight of the map gameobject completely) and the map zoom should start to change to keep the impression of moving up.
Result is : its'kind of working. The logic seems to apply well, exept that when the map is changing it's zoom level, it give the impression that the aircraft is moving horizontally (which is not the case, right now i'm only moving my aircrapft on the Y axis to build this altitude-coherent-behavior.
(and also the view is not realisticly following the altitude but i guess i will fix that by adapting the altitudeCurve / playing with altitude limit where map start following the aircraft y position)
As you can see, if i make variation with the altitude ( going up and down) the aircrapt always land a few meters aways of it's initial position. I think it's due to map center repositionning :
With a greater altitude variation :
(-> the fun fact is that i'm going to put some effort to reproduce this behaviour later, as i'm planning to implement Coriolis force. But right now my aircraft is not supposed to change it's horizontal position.)
and if i comment the line that make the map center reposition itself, it work well :
/// <summary>
/// Updates map position
/// </summary>
private void UpdateMap()
{
// Store last position of GameObject
lastPosition = target.transform.position;
altitude = target.transform.position.y;
// Size of map in scene
Vector2 size = control.sizeInScene;
// Calculate offset (in tile position)
Vector3 offset = lastPosition - map.transform.position - control.center;
offset.x = offset.x / OnlineMapsUtils.tileSize / size.x * map.width * map.zoomCoof;
offset.z = offset.z / OnlineMapsUtils.tileSize / size.y * map.height * map.zoomCoof;
// Calculate current tile position of the center of the map
tx -= offset.x;
ty += offset.z;
////////////////////////////// IT IS HERE : ///////////////////////////////////////////////////////////
// Set position of the map center
// If i comment this line, It will behave propely when moving along Y axis.
// But the "follow-gamobject" logic will be broken if i want to move horizontally the aircraft.
// map.SetTilePosition(tx, ty);
// Update map GameObject position
Vector3 newMapPos = lastPosition - control.center;
if(target.transform.position.y > 100)
{
newMapPos.y = target.transform.position.y - 100;
map.floatZoom = altitudeZoomCurve.Evaluate(altitude / maxAltitude);
}
else
{
newMapPos.y = 0;
}
map.transform.position = newMapPos;
}
Exept of course that it won't follow my aircraft anymore in case of horizontal movement.
So how can i have both behavior - a correct y variatation and a map following the horizontal movement of my aircraft ?
Not sure if relevant but :
- i planned to use elevation
- i also woud like to use horizon. Not sure how it would behave with this followGamobject script though.
- if you think i'm not going in the correct direction to achieve what i want, could you point me toward a better solution ?
Thanks for your time and sorry for the long post