Perci1Join Date: 2011-01-24 Post Count: 1027 |
I'm currently doing this, which works fine;
while true do
wait()
local plr = playerValue.Value
if plr then
local direction = (plr.Character.Torso.Position - bot.Torso.Position) * Vector3.new(1, 0, 1)
bot.Torso.CFrame = CFrame.new(bot.Torso.Position,bot.Torso.Position + direction)
end
end
with 'playerValue' being an object value equal to the player.
However, with lots of NPCs this causes lots of lag. The Script Performance window shows that this is very inefficient, on a large scale at least.
Do you know any more efficient method of making the bot face your character? |
|
WrathsongJoin Date: 2012-07-05 Post Count: 22393 |
ask scripters subforum |
|
|
@above you think with over 2k posts you would have seen atleast once that it states "Scripters" is not for help topics, however the game design section is, are you blind |
|
SulfoneJoin Date: 2010-08-19 Post Count: 8046 |
Loops with very shortest wait() possible are inefficient in general. I recommend having the loop disabled when the player is too far away from the NPC. A separate loop with a high wait such as 10 could be added, with the script right now running whenever the distance away from the player's torso is close enough. Then have the shorter loop break whenever the player is far away enough. |
|
FunseJoin Date: 2012-06-11 Post Count: 7887 |
BodyGyro. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
The double loop would decrease lag when I'm not near the NPC, but the project I'm working on means that I will be near multiple NPCs at once, and it will still lag the same then. The lag spikes don't tend to happen as much when I'm not near them, anyway. I also don't think I want a such a high delay before the loop actually starts.
I don't think a BodyGyro is a good solution. BodyMovers are troublesome, but the BodyGyro's cframe would still need to be set continuously in a loop. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
bump D: |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
... |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
Stop ignoring this... |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
Well screw Roblox forums. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
I was thinking about using the RootJoint but I'm not sure how to use DesiredAngle to face a character. |
|
|
Just an idea, look in the scripts of the gear golden chalice of fame? It has the people spawning all around you, that follow/face you, with no lag.
Just an idea. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
Thanks, but what that gear does is set AutoRotate to true, then just make the bots walk towards you. This makes them automatically face you, but it won't work for me because my NPC isn't going to always be walking directly towards you. |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
local tor = npc.Torso
local you = game.Players.LocalPlayer
while wait() do
tor.CFrame = CFrame.new(tor.CFrame.p,you.Character.Torso.CFrame.p) * CFrame.Angles(math.rad(90),0,0)
end
I'm not sure if I got the rotations correct, but also a more efficient and smooth way of doing this would be to use BodyGyro. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
But that's still in a really fast loop, and a BodyGyro would have to be also in a really fast loop, so it wouldn't really be more efficient, would it? |
|
GoulstemJoin Date: 2012-07-04 Post Count: 7177 |
game.Players.LocalPlayer.Torso.Position.Changed:connect(function(change)
end)
I actually don't know if you can use the Changed event off of a property.. but if so dis is efficient pls. |
|
Perci1Join Date: 2011-01-24 Post Count: 1027 |
You don't use it on a property, but I've tried just using it on the torso, and for some reason when you walk around it's not triggered. If I change the Position in the properties window, it does fire, but me walking around doesn't fire it, oddly enough. |
|