X Wing stops in mid air

Hello!

Currently I’m creating a star wars type of game with a main focus on vehicles, for practice. I was messing around with AssemblyLinearVelocity to create an X Wing, but I’m facing an issue.
The X Wing works fine but when i get close to the border of the baseplate it just stops in mid air. I noticed that when I somehow get the vehicle past the baseplate border, the ship works as intended.

What i have tried to solve this problem is disabling CanCollide on all parts of the model and I rewrote a part of my script, with the same results as before.




Local script

-- // Variables \\ --

-- Services
local players = game:GetService("Players")
local runService = game:GetService("RunService")
local userInputService = game:GetService("UserInputService")
local replicatedStorage = game:GetService("ReplicatedStorage")

local vehicleEvents = replicatedStorage:WaitForChild("VehicleEvents")
local playerInVehicleEvent = vehicleEvents:WaitForChild("PlayerInVehicleRemote")
local fireEvent = vehicleEvents:WaitForChild("FireRemote")

-- Player stuff
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local playerMouse = player:GetMouse()
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("ScreenGui")
local camera = workspace.CurrentCamera
```lua
-- Vehicle stuff
local vehicle = workspace:WaitForChild("XWing")
local vehiclePrimaryPart = vehicle:WaitForChild("MainBody")
local vehicleCamera = vehicle:WaitForChild("PlayerCamPart")
local vehicleSettings = require(vehicle.VehicleSettingsModuleScript)

local playerInVehicle = false
local lastMouseHit = playerMouse.Hit
local mouseMoveDebounce = -math.huge

local newCFrame, newAngleCFrame, asin = CFrame.new, CFrame.Angles, math.asin





-- // Functions \\ --

-- This function sets the velocity to the vehicle
local function setAssemblyLinearVelocity()
	vehiclePrimaryPart.AssemblyLinearVelocity = vehiclePrimaryPart.CFrame.LookVector * vehicleSettings.vehicleMaxSpeed
end



-- // Events \\ --

-- When the button gets clicked
screenGui.EnterBtn.MouseButton1Click:Connect(function()
	playerInVehicle = true
	playerInVehicleEvent:FireServer()
	
	camera.CameraType = Enum.CameraType.Scriptable
end)


-- When the player moves the mouse
playerMouse.Move:Connect(function()
	if not playerInVehicle then return end
	
	local osClock = os.clock()
	
	-- Debouncing
	if osClock > mouseMoveDebounce then
		-- Updates the last mouse position
		lastMouseHit = playerMouse.Hit
		
		mouseMoveDebounce = osClock + 0.1
	end
end)


-- When player uses keyboard/mouse/controller
userInputService.InputBegan:Connect(function(input)
	if not playerInVehicle then return end
	
	if input.UserInputType == Enum.UserInputType.MouseButton1 then
		fireEvent:FireServer(lastMouseHit.Position)
		script.Laser:Play()
	end
end)


-- Fires every frame after physics simulation
runService.Heartbeat:Connect(function()
	if not playerInVehicle then return end
	
	local direction = vehiclePrimaryPart.CFrame:ToObjectSpace(lastMouseHit).LookVector * Vector3.new(0.02, 0.02, 0.02)
	
	setAssemblyLinearVelocity()
	
	--[[ The line below rotates the vehicle. We just arcsin to calculate
	the angle from the direction and apply it to the vehicle ]]--
	vehiclePrimaryPart.CFrame *= newAngleCFrame(0, -asin(direction.X), 0) * newAngleCFrame(asin(direction.Y), 0, 0)
	
	camera.CFrame = vehicleCamera.CFrame
end)
Server script

-- // Variables \\ --

local replicatedStorage = game:GetService("ReplicatedStorage")

-- Events
local vehicleEvents = replicatedStorage:WaitForChild("VehicleEvents")
local playerInVehicleEvent = vehicleEvents:WaitForChild("PlayerInVehicleRemote")
local fireEvent = vehicleEvents:WaitForChild("FireRemote")

-- Vehicle stuff
local vehicle = workspace:WaitForChild("XWing")
local vehiclePrimaryPart = vehicle:WaitForChild("MainBody")
local vehicleWeapons = vehicle:WaitForChild("VehicleWeapons")
local vehicleSettings = require(vehicle.VehicleSettingsModuleScript)

-- Fastcast stuff
local fastCast = require(replicatedStorage:WaitForChild("FastCastRedux"))
local caster = fastCast.new()

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {vehicle}

local castBehavior = fastCast.newBehavior()
castBehavior.RaycastParams = raycastParams
castBehavior.AutoIgnoreContainer = false
--fastCast.VisualizeCasts = true




-- // Functions \\ --

--[[local function onRayHit(cast, result, velocity, bullet)
	local hit = result.Instance
	local enemy = hit:FindFirstAnchestor("XWing")
	
	if enemy then
		
	end
end]]--




-- // Events \\ --

-- When the player just entered the vehicle
playerInVehicleEvent.OnServerEvent:Connect(function(player)
	vehiclePrimaryPart.Anchored = false
	vehiclePrimaryPart:SetNetworkOwner(player)
end)


-- When the player wants to shoot
fireEvent.OnServerEvent:Connect(function(player, mousePos)
	for i, machineGun in ipairs(vehicleWeapons:GetChildren()) do
		local firePoint = machineGun.FirePoint.WorldPosition
		local direction = (mousePos - firePoint).Unit
		
		caster:Fire(firePoint, direction, vehicleSettings.shotSpeed, castBehavior)
	end
end)


--caster.RayHit:Connect(onRayHit)

Any help is appreciated and, if you have suggestions just leave them below!

I’m really not sure about it, since I can’t test and I can’t think of any output errors what I’m about to tell you will cause, what if you do playerMouse.Hit.Position? Cause I believe pointing the mouse into void while not getting any parts, will most likely return nil. Happened to me a few times.

I tried but it still doesn’t work, I tried this method on the Hearbeat event. It’s pretty frustrating too because there’s no apparent reason why the system shouldn’t work. The baseplate has CanColldie off too.

I just tryed to resize the baseplate to check if the issue occured again, and it did, but i toggled off StreamingEnabled and it magically works? Someone could explain?

You aren’t putting your character in the x-wing. My best guess is that once you fly far enough from your character; out of your streaming radius, your physics engine thinks it’s time to stop wasting power on physics you’re too far from.

1 Like

Oh that’s why! You need to use plr.ReplicationFocus so it loads with the character. That’ll fix it. : )

https://developer.roblox.com/en-us/api-reference/property/Player/ReplicationFocus

1 Like

Oh that’s why! Thank you for your response.

Is an alternative way of doing this changing the Focus property of the CurrentCamera?

I do not believe so. The focus only changes position wise. ReplicationFocus is replication and loading, from what I’m aware.

1 Like