#how can i make a part follow the mouse
286 messages · Page 1 of 1 (latest)
i made this ```lua
local uis = game:GetService("UserInputService")
local runservice = game:GetService("RunService")
local camera = workspace:WaitForChild("Camera")
local part = workspace:WaitForChild("MovingPart")
local function mouseRaycast(blacklist)
local mouseposition = uis:GetMouseLocation()
local mouseray = camera:ViewportPointToRay(mouseposition.X, mouseposition.Y)
local raycastparams = RaycastParams.new()
raycastparams.FilterType = Enum.RaycastFilterType.Blacklist
raycastparams.FilterDescendantsInstances = blacklist
local raycastresult = workspace:Raycast(mouseray.Origin, mouseray.Direction * 1000, raycastparams)
return raycastresult
end
runservice.RenderStepped:Connect(function()
local result = mouseRaycast({part})
if result then
part.Position = result.Position
end
end)
rlly???
how would you blacklist it the part though
if you dont then it will just fly into ur screen
Wait is he making the part follow the mouse and not just rotating it? if so then raycasts are perfect are that
im a bit confused on what hes tryna say
omg
im so stupid
i thought he meant actually following the mouse]
@vagrant dirge are you trying to make the part go to the mouse or have it look at the mouse

using cframe is perfect for making the part look at the mouse, whilst raycasts are a good way to have the part follow the mouse
he means rotation
so cframes
yeah
figured

what raycast for
i want it to look at the mouse
basically like an attached gun
best way to do that is to use CFrame.lookat() aslong as its not multiple parts it should be fine
I thought you were tyring to do something else
you could also use CFrame.new(), you can do either
well there's the problem, there are mulitple parts
there's a base part
alright, weld all the part to one part and try and use that part
or you can make a for loop and do the same to each part
well then if i would weld them they couldnt rotate
i could use uhh
i forgor the name
hinges
but the biggest problem is i do not know how to write the script
hinges arnt good if your making it into a full blown pvp game
they are fixes based meaning anything can screw it up
hold on lemme open studio
they are also semi advanced to get hooked up properly
Use the primarypart
show you an ilustration
kk
so a rotating gun?
yes
almost like a helicopter blade?
kinda
hmmmm
but can only go up and down
i also have an idea for one that can move left and right as well
i dont recommend using them
well the game will basically be a bunch of zombies charging or something like that
so obviously guns would need to go up and down as well
well how do i do that
cframes
i dont know how to write the script
that's the problem
also here's another one
this one can move left and right as well
CFrame.lookat(looker, lookat)
litterly the line you need to right to make it lookat the part
if you dont understand cframes i suggest you research them
very usefull
i understand cframes
location, size, orientation
x y z
what am i supose to write in the brackets
brackets?
the ()
looker, lookat
hmm?
to make the rotation easier
what is it
hold on drawing it
kk
if you weld everything to the red part, you could use cframes
both base and secondary part
why would i weld everything to the red part, including the base
then the base would rotate as well
if its not welded with any constraint then it will fall off
well i was thinking of making the red part anchored
but then i think it couldnt work
but with a weld to the base it wouldnt work either
nah
yes you can anchor the base then
well the red part isnt attached to the base
oh
if i attach the red part with the base with a weld, then it would also become anchored
hm, i think i have another idea
and the base was anchored
lemme draw it
k
just one hinge in the middle
therefor it attaches it to the base
but it can still rotate
calculating hinge rotation requires math that i dont even understand
do you mean the hinge?
** You are now Level 7! **
yes
so
the hinge doesnt affect our script
it actually makes it easier
it attaches the rotating part to the base
im not good with physics
its nothing about physics
if it doesnt require scripting why are you putting this in scripting help
bruh
when did i say it doesnt require scripting
i need the part to follow the mouse
which requires scripting
it doesnt need a hinge then
the hinge doesnt require extra scripting
omfg
how many times do i have to explain this
lemme draw more
dude
you DONT need a hinge
you need a hinge
you really dont
let me draw the explination
ask any other scripter here
do you know what the fuck your doing?
DUDE
im trying to help you
WHAT AM I SUPOSE TO DO
im saving you so much time by telling you to use CFRAMES
THE ONLY CFRAME WE WILL BE USING IS ORIENTATION
if your not gonna stick to the same fucking thing then dont expect answers
cframe is orientation
it pretty much is
its rotating and orientation mostly
sure you move the part but you set it to look at something
your always doing something with orientation when working with cframes
they do
tell that to any modeler
it will
wtf is even that
i dont know how to use that either
bruh
im not good at scripting in case you havent notice
mhm
im good at certain things
if you use hinges it wont work and if it does you have to spend hours and hours
if your making something like a helicopter blade then go for hinges
i know more than one game that have what i want to make and work with hinges
destory the island and destroy the ship
they both use hinges
what are you wanting to do at this point because youve comepletely abandoned what you have said originally
just tell me your plan on how to script this thing
how can i tell you my plan if i dont even know what im scripting
i guess every single thing that i just said doesnt fucking matter
2nd time im sending this drawing
ok, lets do without hinge
i honestly dont know how this would work without the hinges
ok
weld the base and red part toghether and blue part and red part toghether
ok
do we like use bodyforces, bodyvelocities?
forgot to mention those are also cframes
they really arnt
no bodyforces
alls you need in the workspace is the base red part and blue part welded all to the red part
and the bottom part anchored
yeah
kinda figured that out, cuz i model, a lot
it doesnt looks good
but i still do it
btw there's another problem
the player sitting on a certain sear can control it
cuz, there will be multiple guns and stuff
is it supposed to be automatic or player controlled
player controled
when somebody goes onto that seat they can control the gun
the bullet thing is not a problem
it's simple really
so why is a problem then
if tis supposed to be player controlled
or are you asking how to make it player controlled
the thing is
i dont know how to make it so that you can control where the gun points after you sit
holy fuck this is going nowhere
obviously the mouse
but
i dont know how to make it so that you can control once you sit in that particular seat
remote events
i have never used them 👍
just sends a signal to another script
use a while true do loop to constently detect if someone is setting
how do i detect that somebody is sitting
its a property on the seat
named?
or you could use get property changed signal
idk its there somewhere
it should be obviouse
i need to know who the player sitting is
so that they can control the gun with their mouse
ik thats what is says
** You are now Level 11! **
the sitters parent would be their character
or the sitter itself would be the humanoid
i have no idea what any of that means
bruh