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: Need help with lookVector

Previous Thread :: Next Thread 
GeniusBuilder is not online. GeniusBuilder
Joined: 20 Jan 2010
Total Posts: 2159
31 Oct 2012 08:25 AM
Is it possible to turn my NPC by 90 degrees from it's lookVector? I know it can be reversed easily (kinda turns 180 degrees) but what about turning into other directions?
Report Abuse
Aurarus is not online. Aurarus
Joined: 22 Dec 2008
Total Posts: 4761
31 Oct 2012 08:31 AM
I don't think so.

lookVector isn't good for exactly this sort of thing.
Report Abuse
GeniusBuilder is not online. GeniusBuilder
Joined: 20 Jan 2010
Total Posts: 2159
31 Oct 2012 08:33 AM
I just want my NPC to turn left or right when there is a wall in front of it.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
31 Oct 2012 09:42 AM
Genius,

Too funny. You want him to turn right. Then what? Turning right won't get him around any wall no matter how small the wall is.

You need an AI which knows what a wall is and how to walk around it. lookVector is not going to do that for you.

Take Speed AI from the catalog. If u study the code, and figure-out how it works, then u will have the answer to your question.

If you just want an NPC which goes where u tell it to go; take NPC Wait Animation.

GL,
Brian
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 09:46 AM
BJ, that is hardly the point, it is probably a maze solver, also I believe you can do that with :cross(Vector3.new(0,1,0)) -- You may have to shift the one to get the right cross product.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
31 Oct 2012 09:53 AM
Chubbx,

That IS the point: If he wants a maze solver, that's 200 lines of code.

The only way to learn to code is to read a lot of code. He might as well reverse-engineer code which does what he wants to do. Trust me lookvector is used, though not the way he imagines (an NPC is not going to walk in the direction it is turned)...
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 09:58 AM
BJ, He is talking about changing the look vector in one piece of script, I highly doubt that all he is going to script is going to be a look vector, he is most likely using a raycast to find the distance, then turning based on that and using a velocity or MoveTo to move the NPC, it is best to just give him the info he needs rather than tell him to go look into shoddily(Yes it is a word) made free models.
Report Abuse
GeniusBuilder is not online. GeniusBuilder
Joined: 20 Jan 2010
Total Posts: 2159
31 Oct 2012 10:11 AM
Yeh I just want it to walk left or right for a while and then follow a player again, if it can't get around the wall by that then it's fine. It's not supposed to go everywhere :P

It's for a RPG btw
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 10:14 AM
Well if you mess with :cross(Vector3.new(0,1,0)) for a bit it should give you the right unit vector.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
31 Oct 2012 10:19 AM
MrChubbs,

You are right,

Genius,

I do not write code on the fly, but here is a chunck from Uber-Shotgun, which turns the Player in the direction he is shooting. It is extremely shoddy code. Just made for fun (The bit that also tilts his whole body up or down is especialy hooky (Yes, used the H-word).

Maybe u caN START WITH THIS. I will try to comment it a bit.

if targ ~= nil then

Hit = CFrame.new(mouse.hit.p) -- This gets "Direction" from a mouse-pointers CFrame, which contains a LOOKVECTOR.

local Torso0 = script.Parent.Parent["Torso"].CFrame

diff = Hit.p.y - Torso0.p.y

if (math.abs(Hit.p.x - Torso0.p.x) > math.abs(diff) + 1) or (math.abs(Hit.p.z - Torso0.p.z) > math.abs(diff) +1) then -- THIS is ALL PRETTY SHODDY.
diff = diff/3
else
diff = diff/6
end

HitPath = Vector3.new(Hit.p.x, Torso0.p.y + diff, Hit.p.z)
script.Parent.Parent.Torso.CFrame = CFrame.new(Torso0.p, HitPath) -- THIS CRAMS THAT MODIFIED LOOKVECTOR INTO THE TORSO OF PLAYER. MAYBE SOMETHING LIKE THIS WILL FOR FOR YOUR NPC.

Dist = (Hit.p - Torso0.p).magnitude

Tool0 = Tool.Handle.CFrame
Place0 = script.Parent.Parent["Right Arm"].CFrame

script.Parent.Handle.Fail:play()

if Dist > 80 then

Hit = CFrame.new(Tool0.p - (Place0.p - Tool0.p + Vector3.new(0,.5,0))*6)

else

hum = targ.Parent:findFirstChild("Humanoid")
if (hum ~= nil) then

c = Instance.new("ObjectValue")
c.Name = "creator"
c.Value = game.Players:findFirstChild(script.Parent.Parent.Name)
c.Parent = hum
hum.Health = hum.Health - math.random(1,32)

end
end
end -- Targ == Nil?

GL,
Brian
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 10:21 AM
Again BJ, he doesn't need a script for an AI, he needs a piece of code to do the requested function. People learn by doing, not by using other people's works. I am not trying to be trolly(trollie?) here, just trying to make a point.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
31 Oct 2012 10:31 AM
>>Yeh I just want it to walk left or right for a while and then follow a player again.


Hey Genius, that is a lot harder than u think or everybody would do it...

But is IS essentialy the psuedo-code for the Script in Speed AI. Here is the super-code of your above sentence:

-- 1 - Look Right or Go left
if Logic == 1 then

if Distance >= 1 then
if ClimbingLadder == false then -- or target.Position.y < torsoPos.y + 4 then
TurnRight()
end -- else go straight or go up
else
TurnLeft()
end

if FireRayAhead() then -- Check straight first. (And Diagonaly left)
TurnLeft()
if FireRay() then -- Check left (And Diagonaly left & back)
TurnLeft()
if FireRay() then
TurnLeft()
if FireRay() then
targpos = torsoPos + Vector3.new(Xdir,0,Zdir)
hum.Jump = true
end -- right
end -- Back
end -- Left
else -- If succesful Ahead then... (We only check RightTurns for a get-out-of-jail-Free card)

if Xdir == OldX and OldZ == Zdir then -- Gracefully exiting Logic 1
Logic = 0
end -- check Goal dir?
end -- Ahead
end -- Logic 1
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 10:34 AM
That is Lua, not pseudo code, pseudo code would be representitive of a language, not a language itself. Also, we are here to answer his first question and that alone, not to mention the fact that what he want to do is actually quite easy.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
31 Oct 2012 11:00 AM
I'm not sure, but I would guess "trollie". The other looks like something u would ride to work in.
Report Abuse
MrChubbs is not online. MrChubbs
Joined: 14 Oct 2010
Total Posts: 4969
31 Oct 2012 11:02 AM
Or something to get food off of as it is pushed by, also, ONE THOUSAND POSTS!
Report Abuse
GeniusBuilder is not online. GeniusBuilder
Joined: 20 Jan 2010
Total Posts: 2159
01 Nov 2012 08:43 AM
If this can't be solved without 30 lines of maths I'll forget about it and let it be some unadvanced AI that won't even try to get past walls.

I can't really believe that there isn't any simple solution, Lua can't be that bad.
Report Abuse
BJCarpenter is not online. BJCarpenter
Joined: 04 Nov 2008
Total Posts: 4416
01 Nov 2012 11:58 AM
For an NPC with no AI, little code, but which u may direct around walls, take NPC Wait Animation.
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