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 » Scripters
Home Search
 

Re: How to make an NPC orient itself perpendicular to a wall?

Previous Thread :: Next Thread 
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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 is not online. DrSaint
Joined: 14 Oct 2009
Total Posts: 18429
16 Jun 2017 03:48 PM
Parallel*
Report Abuse
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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 is not online. 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
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
16 Jun 2017 04:06 PM
Yeah, like I said, I'm terrible at explaining.
Report Abuse
DrSaint is not online. 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
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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 is not online. 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
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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 is not online. 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
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
16 Jun 2017 05:07 PM
hmm...

_,_,v,_ = workspace.FindPartOnRay(...)
torso.CFrame = CFrame.new(torso.CFrame.p,torso.CFrame.p-v)
Report Abuse
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
16 Jun 2017 05:31 PM
Did you try it?
Report Abuse
caca50 is not online. caca50
Joined: 10 Jul 2011
Total Posts: 2037
16 Jun 2017 05:41 PM
Did you try mine
Report Abuse
Wowgnomes is online. Wowgnomes
Joined: 27 Sep 2009
Total Posts: 26255
16 Jun 2017 06:52 PM
Frame lookvextor
Report Abuse
KapKing47 is not online. 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
BunnyBoy26 is not online. BunnyBoy26
Joined: 17 Jun 2010
Total Posts: 5674
16 Jun 2017 08:40 PM
@KapKing47 That is what I did, but you have to negate the normal vector.
Report Abuse
fearlesswee is online. fearlesswee
Joined: 04 Sep 2010
Total Posts: 254
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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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