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: Whats a LookVector?

Previous Thread :: Next Thread 
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 11:46 AM
What does it do and what does it output?
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
04 Mar 2014 11:47 AM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 11:52 AM
A lookVector is simply a vector that has a magnitude of 1.
Also known as normal vectors or unit vectors. They specify only a direction (because their magnitude is 1). This means you can use scalar multiplication on the unit vectors to obtain another vector with X length but the same direction as your unit vector. :D
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 12:04 PM
@AgentFireFox, how could you use this to see if someone was facing an object?
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
04 Mar 2014 12:05 PM
[ Content Deleted ]
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
04 Mar 2014 12:07 PM
u could create a bullet that goes in the direction the player is facing

b = Instance.new("Part",Workspace)
b.Size = Vector3.new(1,1,1)
b.CFrame = PathToTorso.CFrame*CFrame.new(0,0,-2)
bv = Instance.new("BodyVelocity",b)
bv.velocity = PathToTorso.CFrame.lookVector*300

--sorry,i just looooveee typinn scriptss
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
04 Mar 2014 12:10 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 12:14 PM
"@AgentFireFox, how could you use this to see if someone was facing an object?"

The simplest way would be using vector math to find the angle between vectors. This is calculus-level computation, so don't be ashamed if you don't understand it.


A: lookVector of player's face
B: vector between player's face and object (object.Position - player.Character.Head.Position)

The angle between two vectors is the following:

cos( Angle ) = A•B / (|A|*|B|)

Which means (in Lua):

math.cos( Angle ) = A:Dot(B) / (A.magnitude * B.magnitude)

To get the angle, we take the inverse of cosine and apply it to both sides.

math.acos(math.cos( Angle )) = math.acos( A:Dot(B) / (A.magnitude * B.magnitude) )
->
Angle = math.acos( A:Dot(B) / (A.magnitude * B.magnitude) )


This is in RADIANS and will always be between 0 and math.pi, inclusive. This equates to 0 to 180 degrees, inclusive.
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
04 Mar 2014 12:18 PM
[ Content Deleted ]
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
04 Mar 2014 12:21 PM
Uhm, math.abs..?
Report Abuse
Vexedly is not online. Vexedly
Joined: 15 Sep 2006
Total Posts: 7011
04 Mar 2014 12:23 PM
[ Content Deleted ]
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 12:25 PM
In vector notation, |A| = A.magnitude.
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 12:40 PM
It would probably for me be more efficent to simply fire a vector from the object to see if the player is behind it.
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 12:41 PM
*ray
Report Abuse
zars15 is not online. zars15
Joined: 10 Nov 2008
Total Posts: 9999
04 Mar 2014 12:42 PM
No, math is more efficient than ray casting.

Use formula that firefox gave ya, and check if the angle is ~0.
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 12:45 PM
@Firefox, what it said angle in your script?
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 12:45 PM
Using math is tons faster than raycasting because it requires so little steps compared to raycasting. It is also more efficient for the programmer because you could specify ANY angle from 0 to pi to be in view (raycasting would be angle 0 ± angle to edges of object).
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 12:47 PM
Angle is the angle between the player's lookVector and the positional offset vector between the object and the player's head.
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 01:00 PM
I don't really understand it but I did give it ago. I think its better if I just use Raycasting since at the moment it would be easier for me to understand.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
04 Mar 2014 01:39 PM
http://gyazo.com/01457bb609c4b66ebde5a48b7cc4c5ca

Let me know if that helps.
Report Abuse
goglet is not online. goglet
Joined: 01 Jun 2009
Total Posts: 2331
04 Mar 2014 02:16 PM
Thank you very much. I understand the algorithm now and have sucessfully incorperated it into my script. Now I just need to workout how to make the game work-out using an if statement if the player is behind.
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