GIFs of the rotation with and without the tweening
Is there any way to circumvent this?
game.ReplicatedStorage.TweenPosition.OnClientEvent:Connect(function(PositioningData,Rotate)
local Hash, X, Z = Decoder(PositioningData)
local Army = game.Workspace.Armies:FindFirstChild(tostring(Hash))
local ArmyInfo = game.Workspace.ArmyInfos:FindFirstChild(tostring(Hash))
local Goal = {CFrame = CFrame.new(X,3,Z)}
TweenService:Create(Army.PrimaryPart, TweenInfo.new(2, Enum.EasingStyle.Linear), Goal):Play()
end)
game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
local Army = game.Workspace.Armies:FindFirstChild(v.Name)
local Lookat = Vector3.new(mouse.X,1.5,mouse.Z)
print(CFrame.lookAt(Army.PrimaryPart.Position, Lookat))
Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)
Yeah but what’s the point in adding that complexity and sorry I meant the server side which calls the client I didn’t realise that the code snippet was on the client side
I need to understand how your code is working and also why you have added un reasonable complexity, if your not willing to share your code snippets when someone asks and also answer questions about your code you are in the wrong place.
I send the X, Z positions on the army’s Position to the client. But before I do that I simplify the positions using Vector2int16() to send less data and reduce kb/s. Afterwards the position will look like (16,19) when it should be like (16.365,18.97676) the Decoder is there to smoothen out the movement. Hash represents the armys special ID so I can find the army quickly.
local COORD_MULTIPLIER = 5
local function Decoder(PositioningData)
local Block1 = PositioningData[1]
local Block2 = PositioningData[2]
local Hash = Block1.X
local X = Block2.X / COORD_MULTIPLIER
local Z = Block2.Y / COORD_MULTIPLIER
return Hash, X, Z
end
CFrame.lookat dosnt use the decoder vector2int16() stuff
game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
local Army = game.Workspace.Armies:FindFirstChild(v.Name)
local Lookat = Vector3.new(mouse.X,0.5,mouse.Z)
Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)
I know. that’s why I have the decoder to smoothen out movement so it doesn’t look wonky
local COORD_MULTIPLIER = 5
local function Encoder(Hash,X,Z)
X = math.floor(COORD_MULTIPLIER * X + 0.5)
Z = math.floor(COORD_MULTIPLIER * Z + 0.5)
return {
Vector2int16.new(Hash),
Vector2int16.new(X, Z)
}
end
Ok I apologize, But whenever I rotate the army model, its completely fine and faces the direction I clicked in. But whenever I start tweening it, it goes back to staring straight or just completely breaking. Do you have any idea as of why this is happening?
game.ReplicatedStorage.RotateArmyY.OnClientEvent:Connect(function(v,mouse)
local Army = game.Workspace.Armies:FindFirstChild(v.Name)
local Lookat = Vector3.new(mouse.X,0.5,mouse.Z)
Army.PrimaryPart.CFrame = CFrame.lookAt(Army.PrimaryPart.Position, Lookat)
end)
I disable the TweenPosition remote, so when i click it only sends RotateArmyY remote. Result:
Ah I see so when you use tweening you lose the rotational component, for this you need to collapse the two events into 1 or have 1 for Moving and look and have one for just moving heres a code snippet for what to tween into
local x,z = decoder(blah)
local x,y,z = CFrame.LookAt(Vector3.new(x,3,z),Vector3.new(mouse.X,1.5,mouse.Z)):ToEulerAnglesXYZ()
local finalCf = CFrame.new(Vector3.new(x,3,z)) * CFrame.Angles(x,y,z)
-- tween using the finalCf