Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 02:57 AM |
| How could this be done? Raycasting I'm guessing? |
|
|
| Report Abuse |
|
|
|
| 06 Apr 2014 03:10 AM |
| I don't think there's a looking event. |
|
|
| Report Abuse |
|
|
vlekje513
|
  |
| Joined: 28 Dec 2010 |
| Total Posts: 9057 |
|
|
| 06 Apr 2014 03:15 AM |
| I think lookvector or atan2. |
|
|
| Report Abuse |
|
|
Cr0ws
|
  |
| Joined: 16 Aug 2013 |
| Total Posts: 1545 |
|
| |
|
Voidition
|
  |
| Joined: 14 Jul 2012 |
| Total Posts: 1849 |
|
| |
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 06 Apr 2014 07:16 AM |
atan2 is like a corrected atan; it can calculate in four quadrants, instead of just 2.
Now, ray casting wouldn't exactly work, and it would just be better to use a dot product to find the angle between 2 vectors that we know.
One of these vectors represents where the direction the player is looking, so let's use the .lookVector of his head (imagine a line pointing forward out from the head).
The other vector we need is the direction between the player and the brick (as a unit vector).
Here's a diagram I drew in MS Paint http://puu.sh/7Y6fw.png , where θ is the angle between the vectors.
Given that V1 and V2 are the vectors (doesn't matter which is which) the formula for working out theta is as follows:
local cos = V1.x * V2.x + V1.y * V2.y + V1.z * V2.z angle = math.deg(math.acos(cos))
The angle will be between 0 and 180: 0 represents the player looking directly at the block, while 180 represents the player looking in the dead opposite direction.
You can then compare this angle, and harm the player if they are looking within a certain threshold, like so
if angle <= 30 then --harm player end
Hope that's helpful |
|
|
| Report Abuse |
|
|
| |
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 03:38 PM |
@RoflBread; Yeah, that sounds useful if I was good enough to understand it..
But the game I'd use it in forces you to be in first person, so I was thinking maybe a "rig" that welds parts facing out from your face/torso, if the brick touches the rig, it harms you. |
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
| |
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 06 Apr 2014 03:57 PM |
@Kinnis,
The way I posted would still work with first person, but your way could work too. Up to you :P |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 06 Apr 2014 04:01 PM |
| I would not mind writing it out for you, either :-) |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 05:14 PM |
I normally try not to ask people to write script for me, but this is a bit important, so if you want you can. Let's name the brick "body" Alright? Alright :> |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 05:18 PM |
| Also it needs to constantly harm them as long as they're looking at it. If they're looking at it their health slowly drains. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 11:58 PM |
Also, the brick has to be actually visible. If a brick is between them blocking the view it's fine.
This is why I think it's only possible by raycasting. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 06 Apr 2014 11:59 PM |
Have a GUI that points a constant ray in whatever direction the player looks. The ray is a cylinder large in width. If the ray touches the brick damage is dealt.
Not sure how to make it drain the health rather than do damage per touch though. |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2014 12:15 AM |
Kinn..
Ray.new
doesn't create a physical object.. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 07 Apr 2014 12:17 AM |
o
I've never used them.
But the rig idea still stands possible. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 07 Apr 2014 03:34 AM |
Bump. I'd need help making the rig too. |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 07 Apr 2014 06:50 AM |
In a local script in StarterGui
p = game.Players.LocalPlayer c = p.Character target = Workspace.THE_HARM_BRICK -- camera = Workspace.CurrentCamera
function raycast() local dir = camera.CoordinateFrame.lookVector local ray = Ray.new(c.Head.Position, dir*999) local hit, pos = Workspace:FindPartOnRay(ray, c) if hit == target then c.Humanoid:TakeDamage(1) end end
while wait() do raycast() end
But that only harms them if are looking right at it (cursor on it in 1st person). |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 07 Apr 2014 07:34 AM |
K this got complicated fast, haha. Spent a while making this, see what you think:
http://pastebin.com/UxhvFwvz
Still in a local script in startergui or wherever. This script assumes the kill brick is a single part, not a model. |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
|
| 07 Apr 2014 07:45 AM |
| The script won't harm you if there is something between you and the brick; and it takes into account your field of view instead of just damaging you when a single ray hits the harm brick. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 07 Apr 2014 08:40 AM |
Oh wow, that works amazingly actually! Though it works better with an angle of < 60 but I edited it. |
|
|
| Report Abuse |
|
|
RoflBread
|
  |
| Joined: 18 Jun 2009 |
| Total Posts: 3803 |
|
| |
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 07 Apr 2014 08:48 AM |
| Thanks mate, I'll definitely give you credit for anything I use it in. |
|
|
| Report Abuse |
|
|
Kinnis97
|
  |
| Joined: 21 Feb 2010 |
| Total Posts: 1683 |
|
|
| 07 Apr 2014 10:08 PM |
I have the target set to a brick inside a model, and the bricks's kind of merged with other bricks. (Inside each other.) It now only harms the player if they look directly at it, and/or if they're close to it. It's really vague and the problem changes slightly every time I try to fix it. I tried making the target a lone brick in the Workspace but it still doesn't work right. Maybe it's the place, or the fact that it's being cloned into the player's PlayerGui, not placed in the StartGui. |
|
|
| Report Abuse |
|
|