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
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
|
| 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
|
  |
| 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
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
|
| 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
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
|
| 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
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
zars15
|
  |
| Joined: 10 Nov 2008 |
| Total Posts: 9999 |
|
| |
|
Vexedly
|
  |
| Joined: 15 Sep 2006 |
| Total Posts: 7011 |
|
| |
|
|
| 04 Mar 2014 12:25 PM |
| In vector notation, |A| = A.magnitude. |
|
|
| Report Abuse |
|
|
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
|
  |
| Joined: 01 Jun 2009 |
| Total Posts: 2331 |
|
| |
|
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
|
  |
| Joined: 01 Jun 2009 |
| Total Posts: 2331 |
|
|
| 04 Mar 2014 12:45 PM |
| @Firefox, what it said angle in your script? |
|
|
| Report Abuse |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 04 Mar 2014 01:39 PM |
http://gyazo.com/01457bb609c4b66ebde5a48b7cc4c5ca
Let me know if that helps. |
|
|
| Report Abuse |
|
|
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 |
|
|