generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: SetDesiredAngle according to mouse position

Previous Thread :: Next Thread 
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 10:46 PM
I have an arm in Camera that I want to move according to where the mouse is. So if the mouse is at the top of the screen, I want the arm to point upward... how can I do this?
Report Abuse
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 10:48 PM
I tried motor1:SetDesiredAngle(math.atan(mouse.Y)) btw
Report Abuse
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 10:52 PM
and the arm only moves at like the top 10 pixels of the screen
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
11 Oct 2013 10:57 PM
(In a LocalScript)

local part = Workspace.Part
repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Move:connect(function()
local scr = Instance.new("ScreenGui",player.PlayerGui)
local maxy = scr.AbsoluteSize.Y/2
scr:Destroy()
part.CFrame = CFrame.new(part.Position)*CFrame.Angles((maxy-mouse.Y)/maxy*math.pi/2,0,0)
end)
Report Abuse
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 11:03 PM
I'm using Motor6D though :p
there's a bunch of other lines but they're not important... I need to get the right angle at
motor1:SetDesiredAngle()


--
menu.Event:connect(function()
local fakeBody, motor1 = menuAnim()
mouse.Move:connect(function()
local y = mouse.Y
motor1:SetDesiredAngle(math.atan(y))
end)
end)
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
11 Oct 2013 11:25 PM
local scr = Instance.new("ScreenGui",player.PlayerGui)
local maxy = scr.AbsoluteSize.Y/2
scr:Destroy()
motor1:SetDesiredAngle((maxy-mouse.Y)/maxy*math.pi/2)



Note though, that player needs to be defined. Also, don't put connections to functions inside of other functions. That's silly.
Report Abuse
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 11:28 PM
Thanks! And player is defined, I only posted a portion of the script..
and why can't I put connections into other functions? It works fine!
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
11 Oct 2013 11:31 PM
In this case it would, but if I'm not mistaken you're basically creating a new function every time 'Event' is called from menu - one that's never disconnected. Therefore, is 'Event' was called twice, the mouse.Move function would also be called twice, because it's still there from the first call of 'Event', if that makes any sense.
Report Abuse
chairman154 is not online. chairman154
Joined: 04 Jan 2013
Total Posts: 126
11 Oct 2013 11:32 PM
no, I didn't include it in the script I showed, but the event disconnects itself because I have it like

local loop = mouse.Move:connect(function()
if not something then loop:disconnect() end
end)
Report Abuse
MHebes is not online. MHebes
Joined: 04 Jan 2013
Total Posts: 2278
11 Oct 2013 11:43 PM
Oh, okay, good :)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image