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: Make a block look towards a mouse, how?

Previous Thread :: Next Thread 
ArcadeSona is not online. ArcadeSona
Joined: 02 Nov 2013
Total Posts: 57
20 Jun 2014 11:05 PM
Title says it all. I've already done this before on as3 with 2d trig. How do I do this on roblox?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:07 PM
define mouse

block.CFrame = CFrame.new(somecframehere, mouse.Hit.p)

the second argument of cframe is focus
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 11:07 PM
Probably just CFrame.

CFrame has a constructor that goes something like this:

CFrame.new(Vector3, Vector3)

The first Vector3 is the position that the part will be placed on, and the second is the position that it will be facing. You can get the 3D 'position' of the mouse with the Hit property of the PlayerMouse

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
AMasterProgrammer is not online. AMasterProgrammer
Joined: 02 Apr 2013
Total Posts: 1608
20 Jun 2014 11:10 PM
pos1, pos2 = Vector3.new(0,10,0), Vector3.new(0,0,10)
off = (pos2 - pos1)
mag = math.sqrt(off.x^2 + off.y^2 + off.z^2)
unit = Vector3.new(off.x/mag, off.y/mag, off.z/mag)
cf = CFrame.new(pos1) * CFrame.Angle(-math.asin(unit.y),math.atan2(unit.x, -unit.z),0)
Report Abuse
ArcadeSona is not online. ArcadeSona
Joined: 02 Nov 2013
Total Posts: 57
20 Jun 2014 11:12 PM
Wow, fast reply. Thanks, it works now.
Report Abuse
AMasterProgrammer is not online. AMasterProgrammer
Joined: 02 Apr 2013
Total Posts: 1608
20 Jun 2014 11:12 PM
use mine, if you show people it you'll look cool :)
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:15 PM
@AMaster

Where do you learn Ttig for 3D, any sites you specifically recommend, or should I just search?
School does not teach me anything that I can apply here.
(Still do not know how asin/acos/atan is different from the normal trig)
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 11:18 PM
Are you familiar with SOH CAH TOA?

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
AMasterProgrammer is not online. AMasterProgrammer
Joined: 02 Apr 2013
Total Posts: 1608
20 Jun 2014 11:18 PM
i would recommend KhanAcademy.org to learn trig.
they also have cool programming section with crytography and stuff, but it looks like its made for 4th graders :p

gl on learning trig. if you want add me on skype and i can give you some help with it.

my skype: braden.godley
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 11:19 PM
I could make a little post right now that explains asin/acos/atan if you'd like

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:20 PM
Yes swim I am, but not asin/acos/atan and I am not familiar with using with for circles or anything special.
I only know triangles.

Amaster: Thanks.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:27 PM
Searched it up, acos/etc. is inverse.
Going to look into it more, and you don't need to swim.
Thanks anyway.
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 11:27 PM
Perfect! Then this will be easy

So as you know, sin(angl) = opposite / hypotenuse. But what if we know what the opposite and the hypotenuse are, but not the angle? Well, then we use asin! So we're going to put asin() around each side of the equation like this:

asin(sin(angl)) = asin(opposite / hypotenuse)

asin is the inverse of sin, so they cancel each other out, so we end up with this equation

angl = asin(opposite / hypotenuse)

And now we've found our angle! YAY MATH!

Does that make sense? Anything that isn't clear?

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
swimguy777 is not online. swimguy777
Joined: 30 May 2009
Total Posts: 17092
20 Jun 2014 11:27 PM
@dueling

TOO LATE :D

-[::ƧѡÎḾḠΰῩ::]-[::Helper of Scripting and Writer of Wikis::]
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jun 2014 11:29 PM
Thanks for the help.
Even though I searched it up :L
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