I made a script that sends the mouse LookVector to server, then the server throws Molotov based on the Lookvector. The problem is that when facing one direction it throws backwards.
Server:
script.Action.OnServerEvent:Connect(function(plr,mousehitpos,mouselookvector)
local Handle = script.Parent.Handle:Clone()
local d = script.Parent.Handle
d.Transparency = 1
local Velocity = Instance.new("LinearVelocity")
local Multiply = 35
local Yforce = (mouselookvector.Y*Multiply)
local Zforce = -(mouselookvector.Z*Multiply+2)
print(Yforce.." / "..mouselookvector.Y)
print(Zforce.." / "..mouselookvector.Z)
Velocity.VectorVelocity = Vector3.new(0,Yforce,Zforce)
Velocity.Parent = Handle
Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
Velocity.Attachment0 = Handle:FindFirstChildWhichIsA("Attachment")
game.Debris:AddItem(Velocity,.2)
Handle.Transparency = 0
Handle.Position = d.Position
Handle.Name = "Molotov"
Handle.CanCollide = true
Handle.CanTouch = true
Velocity.MaxForce = 1000
Handle.Parent = workspace
Handle.Explode.Disabled = false
end)
Client:
--// Functions
local function Throw()
script.Parent.Action:FireServer(Mouse.Hit.Position,Mouse.Hit.LookVector)
end
--// Script
wait(1)
Tool.Activated:Connect(function()
Throw()
end)
The only direction it throws correctly is this direction.
Rotating 90 degrees or -90 degrees will cause it to have no velocity and not throw. Rotating 180 degrees from that point will make it throw backwards.
can’t you just reverse the velocity’s force?
1 Like
If I do that, then the direction it throws backwards is going to be the other way around. It will still throw backwards one direction
i don’t really understand, please explain
When the client sends the mouse LookVector to the server, the server multiplies the lookvector on the Y and Z axis. Then it applies that velocity to the molotov using Linear Velocity. The problem is that when facing the other direction and sending the mouses LookVector to the server, it does not reverse.
maybe reverse the yorce and the zforce
The ZForce is already reversed. If I reverse the YForce, it would still throw backwards
Have you tried instead of multiplying the YForce
and ZForce
, just directly referencing mouselookvector
as the velocity?
1 Like
I have tried that, but it returns a decimal for LookVector, so it applies something like 0.3481596186, which means it does not have any power when throwing it
This might not work but what if you used math.ceil
to round to the nearest integer and then multiplying mouselookvector with Multiply?
mouselookvector * Multiply
I used Math.Ceil but it returns 0
local Yforce = math.ceil((mouselookvector.Y--[[*Multiply]]))
local Zforce = math.ceil(-(mouselookvector.Z--[[*Multiply+2]]))
What about, instead of reversing the whole Zforce, you just reversed the multiplication?
mouselookvector.Z * -Multiply
or
Velocity.VectorVelocity = Vector3.new(0, mouselookvector.Y * -Multiply, mouselookvector.Z * -Multiply)
quick question (sorry if this is a bit unrelated)
why is there no XForce variable here
local Handle = script.Parent.Handle:Clone()
local d = script.Parent.Handle
d.Transparency = 1
local Velocity = Instance.new("LinearVelocity")
local Multiply = 35
local Yforce = (mouselookvector.Y*Multiply)
local Zforce = -(mouselookvector.Z*Multiply+2)
print(Yforce.." / "..mouselookvector.Y)
print(Zforce.." / "..mouselookvector.Z)
Velocity.VectorVelocity = Vector3.new(0,Yforce,Zforce)
I just used the cameras CFrame at Y
script.Action.OnServerEvent:Connect(function(plr,mousehitpos,mouselookvector,camcframe)
if db == true then
return
end
db = true
local Handle = script.Parent.Handle:Clone()
local d = script.Parent.Handle
d.Transparency = 1
local Velocity = Instance.new("LinearVelocity")
local Multiply = 4
local Yforce = math.floor(camcframe.Y/2*Multiply)
local Zforce = -math.floor(Yforce*Multiply)
print(Yforce.." / "..mouselookvector.Y)
print(Zforce.." / "..mouselookvector.Z)
Velocity.VectorVelocity = Vector3.new(0,Yforce,Zforce)
Velocity.Parent = Handle
Velocity.RelativeTo = Enum.ActuatorRelativeTo.Attachment0
Velocity.Attachment0 = Handle:FindFirstChildWhichIsA("Attachment")
game.Debris:AddItem(Velocity,.2)
Handle.Transparency = 0
Handle.Position = d.Position
Handle.Name = "Molotov"
Handle.CanCollide = true
Handle.CanTouch = true
Velocity.MaxForce = 1000
Handle.Parent = workspace
Handle.Explode.Disabled = false
wait(5)
db = false
d.Transparency = 0
end)
script.Parent.Action:FireServer(Mouse.Hit.Position,Mouse.Hit.LookVector,workspace.CurrentCamera.CFrame)
end
variable’s still say mouselookvector but it’s the camera
system
(system)
Closed
November 7, 2023, 5:55pm
#15
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.