|
| 16 Jun 2017 12:23 PM |
| So, I'm making an NPC that is supposed to avoid objects. ROBLOX's pathfinding API doesn't really work in environments without ridiculously thick walls. As such, I have made a system that uses raycast to detect objects and avoid them as such. It works decently well, but the AI tends to get stuck if they are looking at the wall at an odd angle. To remedy this, I need the NPC to automatically face directly at the wall, at the same angle as the wall. I dunno how to do this. |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 03:28 PM |
| Quick lil' bump. If you are all confused as to what I mean (I'm terrible at describing stuff), I could whip up an illustration or something. |
|
|
| Report Abuse |
|
|
DrSaint
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 18429 |
|
| |
|
|
| 16 Jun 2017 03:51 PM |
| No, not parallel. Parallel lines head in the same direction. Perpendicular intersect. I want the NPC to be facing into the wall, so it is perpendicular with it's surface. |
|
|
| Report Abuse |
|
|
DrSaint
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 18429 |
|
|
| 16 Jun 2017 03:56 PM |
| Ah, i'm confused by "Look directly at the wall with the same angle" |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 04:06 PM |
| Yeah, like I said, I'm terrible at explaining. |
|
|
| Report Abuse |
|
|
DrSaint
|
  |
| Joined: 14 Oct 2009 |
| Total Posts: 18429 |
|
|
| 16 Jun 2017 04:13 PM |
| Yea because perpendicular implies a 90 degree angle, meaning they intersect, which I can't imagine would be useful |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 04:14 PM |
| That is exactly what I want, I want the AI to face directly into the wall. If there were an arrow coming from the NPC's chest, it should intersect the wall at a 90 degree angle. |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 16 Jun 2017 04:20 PM |
Um...
local hit, pos = --Ur raycasting stuff Torso.CFrame = CFrame.new(Torso.Position, pos)
Is this what ur looking for?
|
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 04:48 PM |
| No, that will cause the NPC to face where the ray hits. The problem is, the ray is emitted from the torso, to a point 5 studs in front of the torso. He is already facing in that direction. |
|
|
| Report Abuse |
|
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
|
| 16 Jun 2017 04:55 PM |
An idea:
Two rays, one coming out of left side of torso, one from right side, and compare the distance between the two, and rotate the AI accordingly. |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 05:07 PM |
hmm...
_,_,v,_ = workspace.FindPartOnRay(...) torso.CFrame = CFrame.new(torso.CFrame.p,torso.CFrame.p-v) |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 05:12 PM |
| Again, this would cause the NPC to face where the ray hits, which is already in front of the torso. |
|
|
| Report Abuse |
|
|
| |
|
caca50
|
  |
| Joined: 10 Jul 2011 |
| Total Posts: 2037 |
|
| |
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
| |
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 16 Jun 2017 08:27 PM |
How about this?
local hit, pos, norm = --Raycasting Torso.CFrame = CFrame.new(Torso.Position, Torso.Position + norm)
|
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 08:40 PM |
| @KapKing47 That is what I did, but you have to negate the normal vector. |
|
|
| Report Abuse |
|
|
|
| 16 Jun 2017 09:25 PM |
| I'm sorry BunnyBou26, I tried yours, and it worked exactly as I needed. I just saw it was similar to an earlier one, and kinda assumed it was the same. Upon further inspection, I noticed a third variable for findpartonray to return. I looked it up, and found out surfacenormal is a thing. Thanks! |
|
|
| Report Abuse |
|
|
KapKing47
|
  |
| Joined: 09 Sep 2012 |
| Total Posts: 5522 |
|
|
| 17 Jun 2017 07:34 PM |
Oh sry, I just skimmed past ur answer and thought that no one mentioned the normal vector being returned by the ray.
|
|
|
| Report Abuse |
|
|