So I’m trying to make a ship that will position on the surface of parts
like this:
https://gyazo.com/42bbdc6e8cc234a427d1dbc56c1ccfb6
but I have pathfinding stuff that tweens the position of the ship to where I want it to move into
this is the code that makes it go in the surface only
local function updateShPosY()
local shipOrPos = sh.Position
local ray_ = Ray.new(shipOrPos, Vector3.new(0, -1, 0) * 10)
local rayHit_, rayPos_ = workspace:FindPartOnRayWithIgnoreList(ray_, getcd())
local _magnitude = (rayPos_ - shipOrPos).Magnitude
if rayHit_ ~= nil and _magnitude <= 10 then
local oPos_ = sh.Position
local fPos = Vector3.new(oPos_.X, oPos_.Y - _magnitude + sh.Size.Y / 2 / 2, oPos_.Z) --sh.Position - Vector3.new(0, _magnitude, 0) + Vector3.new(0, sh.Size.Y / 2 / 2, 0)
tween:Create(sh, TweenInfo.new(.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out), {
Position = fPos
}):Play()
end
end
run.RenderStepped:Connect(function()
local targetPos = Get3DPosition(mouse.X,mouse.Y)
ball.Position = targetPos
updateShPosY()
end)
but when its moving the ship, it bugs out as shown in the video
this is the code where it moves the ship
so basically I raycast on the bottom of the ship to get the surface Y position that I want the ship to be in
but when it path finds its way (using tween), it does this:
https://gyazo.com/e485d42a3e777a8a0161fd5f44a63bf2
any ideas on how to make it work while moving?