Trying to improvement plane movement - How do I do it?

Hi all,

I have a pretty rudimentary plane flight system, as seen in the attached video:

I got inspiration from the below videos:
Jet Fighter Game Android #aircombat #androidgame #battlefield #jetfighter #gaming
Aircraft Strike: Jet fighter Plane Games #gaming #androidgame #jetfighter #aircombat #fighterjet
War Thunder mobile- jet kill

Obviously, some of these videos have some advanced movement than what I want, but I want to have a plane where the player moving his or her cursor move the camera which then moves the plane, rather than the cursor moving the plane that then moves the camera.

I also would like a way to figure out to pin the plane model being static and constantly in the bottom half of the screen. Some of the above videos have that feature, but they very often allow for the player to “free” the camera. Not exactly what I would want.

Here’s the script that currently controls the plane. It’s pretty basic:

local vehicle = script.vehicle.Value
local engine = vehicle.Engine
local FORCE = engine.LinearVelocity
local GYRO = engine.AlignOrientation
local plr =  game:GetService("Players").LocalPlayer
local Mouse = plr:GetMouse()
local flying = false
game:GetService("RunService").Stepped:Connect(function(Time: number, DeltaTime: number)
	if not flying then return; end;
	local BankAngle = GetBankAngle(Mouse)
	FORCE.VectorVelocity = (engine.CFrame.lookVector)*100
	GYRO.CFrame = (Mouse.Hit*CFrame.Angles(0,0,BankAngle))
end)

What must I do to get the desired effect?

1 Like

I think you could have the camera be a fixed offset above and behind the camera pivot point. I don’t know whether this is what you actually want, though. Have you tried mocking up how you want it to look? you could do this by manually place the plane, camera, enemy planes, and reticle in studio and taking screenshots. If the plane can point up or down at a high angle, just having an offset vertically might not work good.

1 Like

In the attached video, using some code I got from ChatGPT, I’ve gotten pretty close to what I want. Obviously I’m going to have to play around with the camera positioning for the ideal position, but I still would like to make the movement of the plane less “herky-jerky”

Ok I see what you mean now. That looks hard to aim.

1 Like

So the plane goes towards where the camera is facing? You could use the camera’s look vector or raycast from the camera.

I think you essentially need the camera to be detached from the plane. Then, the plane turns towards that direction. You have to consider this though, the plane will still be moving in the wrong direction for a bit while its turning. So if you are going one way then try to turn left 90 degrees, you will see your cursor sliding to the right until the plane aligns with that direction. I don’t know if thats a problem but it will have consequences for how aiming feels.
To actually do it, you just need a function that rotates a vector towards another. There a different was to do it and chatgpt (or the Roblox Assistant) probably knows how to do it. Then you can rotate the planes speed towards the cursor direction.

1 Like

Better improvement:

An issue seen above is, you can only have the plane go so high or low of an angle and then it starts bugging out - you can’t do a “loop” in-air with it. I would like to fix that.

The planes in the game won’t have any heat-seeking functionality, they will pretty much just be flying machine guns like seen here

Do you see the issue where, when you’re turning, the cursor is sliding across the background? It’s also rotating with the plane’s rotation. I think this will be really hard to aim. At the minimum the camera should not roll with the plane.

This is a really old game but take a look at this. It’s known for having really good controls on a console with a famously bad controller, the N64:

  • The aiming reticle uses the full width and height of the screen
  • The ship is thin, so unless you are in the very middle of the screen aiming straight forward, it doesn’t block your aim.
  • The reticle is drawn on top of the ship so it doesn’t go out of view
  • The camera is just far back enough that you can see enemies at the min and max height, it doesn’t pitch up and down or roll.
  • The camera is not following the direction of the ship, instead it is watching a point that is a fixed distance in front of the ship, but only follows it on the X axis.
2 Likes

The cursor “sliding across the background” was my own doing by my own input.

In actual practice the “aiming” part of the plane/its crosshair will be as such:

It will be a static thing while the player’s crosshair will be unlocked.

I am personally not opposed to having the camera follow the player while they roll - I find it pretty neat and not disorienting. However, rolling/going upside down can really make the camera system freak out

Pretty solid controls. Only complaint I would have is that the plane model is barely visible - given that the game is from the 90s, I could imagine they wouldn’t want the extremely low poly plane model to be front-and-center during the gameplay.

However, 30 years later, I am using pretty detailed and nice WW2-era planes that I would like to be displayed and very much visible during air-to-air combat.

How would this be done via code? I am interested in testing this out with the plane system(s) I’ve shown above. I would like to include the Y axis since there will be a lot of altitude changing (there is no cap of altitude and since these are WW2 planes we are talking about, the dogfighting will have very steep climbs and descents). I can agree with the camera ignoring roll.

This is the camera following script that ChatGPT spit out at me, and I use a very slightly edited version of it:

-- Set the camera to the bottom half of the screen
local screenSize = workspace.CurrentCamera.ViewportSize
local bottomHalf = screenSize.Y / 2

-- Function to update camera position
local function updateCamera()
	if vehicle then
		-- Get the position and orientation of the plane
		local planePosition = vehicle.PrimaryPart.Position
		local planeOrientation = vehicle.PrimaryPart.CFrame

		-- Set the camera's CFrame to follow the plane
		camera.CFrame = planeOrientation * CFrame.new(0, 5, 15) -- Adjust the offset as needed
	end
end

-- Connect the update function to the RenderStepped event
runService.RenderStepped:Connect(updateCamera)

Look in the direction of the plane by some fixed distance. Based on the mouse position, angle the direction left or right, or up or down. Wherever this point lands, imagine a vertical line going from the ground up through it. The camera looks at this vertical line and is dragged towards it to maintain a constant distance. This will allow the player’s plane to “swing” behind the line like it does in the star fox video.


To have it work with the Y axis too, you could have the camera follow the green line up a bit towards where the red line hits it.

1 Like

Could you make a quick sample code? Camera manipulation has never been my strong suit hence why I used ChatGPT for the initial stuff. Lol.

If I can do it quickly with the assistant I’ll send it to you.

1 Like