0
\$\begingroup\$

I'm building a simple 2.5D Dogfighting game, kinda similar like this one: https://gfycat.com/PleasantDeterminedArcherfish for the moment my movement works like this:

    if (Input.GetKey("left"))
    {
        transform.Rotate(0, 0, rotation);
    }

    if (Input.GetKey("right"))
    {
        transform.Rotate(0, 0, -rotation);
    }

    if (Input.GetKey("up"))
    {
        if (speed <= maxspeed)
            speed += speedIncrease;
        if (gravity > 0)
            gravity -= speedIncrease;
    }

    if (Input.GetKey("down"))
    {
        if (speed > 0f)
            speed -= speedIncrease;

        if (speed <= 0f)
            speed = 0;

        if (gravity < 1.0f)
            gravity += speedIncrease;
    }


    transform.Translate((Vector3.down * gravity), Space.World); //This is for the fake gravity
    transform.Translate(new Vector3(0, 1 * speed, 0)); //This applies the forward speed

I tried to create the gravity by myself, so that I would be able to lower the gravity, at higher speeds, so that I can achieve an "uplift" effect, like in reality. But now I wanted to let my model face the movement direction and all solutions, I found to solve this problem use the rigidbody.velocity, which is zero in my case. Is there another case to solve this problem? Or maybe even a better solution to achieve a similar movement like in the gif than mine? Maybe adding force instead of Translate?

\$\endgroup\$
  • \$\begingroup\$ Possible duplicate of A simple flight simulator \$\endgroup\$ – Philipp Apr 4 '16 at 13:39
  • \$\begingroup\$ I guess not, since my main question is how to achieve "face the direction of movement" without 'rigibody.velocity' \$\endgroup\$ – TobiasW Apr 4 '16 at 13:44
  • \$\begingroup\$ Then you might want to edit the last three sentences of your question, because they give the impression you are open to any suggestions how this problem could be solved. \$\endgroup\$ – Philipp Apr 4 '16 at 15:10
  • \$\begingroup\$ Tell me if I'm wrong, but from your code I imagine that your problem is that your "ship" si rotating correctly but it actually only goes up or down (instead of moving accordingly to its rotation). Am I correct? \$\endgroup\$ – lvictorino Apr 4 '16 at 17:03
  • \$\begingroup\$ No it moves correctly, since it's always moving "local forward", there is just the point that the "nose" of the plane does not fall down, when the plane is losing speed and drops down. \$\endgroup\$ – TobiasW Apr 5 '16 at 6:07
1
\$\begingroup\$

This is actually a multi-particle system based game. The position of the mouse cursor is used to determine the X and Y of the plane. This is done by splitting the screen into quads. Each quad giving the negative and positive values for each axis.

Mouse_X = MousePosition.X - (1023 / 2)
Mouse_Y = MousePosition.Y - (767 / 2)

enter image description here

The plane on the other hand is only a point on a graph trying to follow the cursor through simple 'if' commands. The background is only a graph whos min and max change to the increase of distance from the center.

\$\endgroup\$
  • \$\begingroup\$ Thanks for the explanation, but I actually don't want to make exactly the same game, this is why I want to add gravity and acceleration stuff. And I'm not sure how to add the dropping nose of the plane... So when my plane is getting slower, it should start to fall down and the nose should start to point slowly to the ground \$\endgroup\$ – TobiasW Apr 8 '16 at 6:06
  • \$\begingroup\$ I see, it does sound like you want to make a simulator instead \$\endgroup\$ – Daniel Strickland Apr 8 '16 at 7:11
  • \$\begingroup\$ The nose dropping is due to rotational moments caused from the tail. If you take the amount of force and multiply it by the distance from the center of gravity, you will know how much force you will have to rotate the plane. So-- ( Air Density*Velocity^2*Surface Area)*Distance = Torque \$\endgroup\$ – Daniel Strickland Apr 8 '16 at 7:31
  • \$\begingroup\$ These videos I made might help. youtube.com/watch?v=QcX1A6zZN3k \$\endgroup\$ – Daniel Strickland Apr 8 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.