AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
In my gun, I have this bit of code. It makes your gun look up and down. It starts once you equip the gun.
local RenderAnimation
local function RenderStepped()
if Equipped then
Character["Right Arm"].LocalTransparencyModifier = 0
Character["Left Arm"].LocalTransparencyModifier = 0
Character.Torso.Neck.C1 = CFrame.new() -- 1
Character.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((LocalMouse.Hit.p - LocalMouse.Origin.p).unit.y), 0, 0) -- 2
else
Character["Right Arm"].LocalTransparencyModifier = 1
Character["Left Arm"].LocalTransparencyModifier = 1
RenderAnimation:disconnect()
end
end
RenderAnimation = game:GetService("RunService").RenderStepped:connect(RenderStepped)
The lines I marked as 1 and 2 cause just about all of the lag. In Script Performance window, I tested it and just those 2 lines can make it go up to about 3.5%, which is really, really bad. Phantom Forces is far more complex, yet their guns don't lag.
Any advice? |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
haracter.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((LocalMouse.Hit.p - LocalMouse.Origin.p).unit.y), 0, 0)
I got this line from a free model that is something like 2 years old, and I'm guessing Mouse.Y wasn't a thing back then, and is probably much faster. How can I convert it to Mouse.Y, since all of the math it's doing seems to be lagging. |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
Actually, Mouse.Y wouldn't work because it's a first person only gun.
well there goes that |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
Bump
|
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
Full section* called on equipped
local function RenderSteppedLocal()
game.Workspace:WaitForChild(Player.Name)
local RenderAnimation
local function RenderStepped()
if Equipped then
Character.Torso.Neck.C1 = CFrame.new()
-- Character.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(0, 0, 0)
Character.Torso.Neck.C0 = CFrame.new(0, 1.5, 0) * CFrame.Angles(math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), 0, 0)
Character["Right Arm"].LocalTransparencyModifier = 0 -- May need to remove this. Causes 0.1-0.2% on localscript.
Character["Left Arm"].LocalTransparencyModifier = 0
else
Character["Right Arm"].LocalTransparencyModifier = 1
Character["Left Arm"].LocalTransparencyModifier = 1
RenderAnimation:disconnect()
end
end
RenderAnimation = game:GetService("RunService").RenderStepped:connect(RenderStepped)
end |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
Should I be worried about it getting up to 3.5%? The wiki says so, but sometimes it doesn't always mean it's laggy. |
|
71428Join Date: 2015-08-06 Post Count: 339 |
RenderStepped is currently acting up for me too. |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
Was it not before? Just a few days ago was the first time I ever checked the script performance window for it. |
|
71428Join Date: 2015-08-06 Post Count: 339 |
Well I don't know for you but for me there's definitely been a change with the RenderStepped. I can feel it in my bones. |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
b |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
b2 |
|
|
Instead of renderstepped, try using mouse.Move
|
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
No. |
|
|
If you are constantly using the same CFrames, you should make them a variable. That way you don't need to create one every 1/60 of a second (approx).
As well, you can try to make the math functions local.
Is there a reason you need to set constantly the Neck.C1? I wouldn't think so.
In fact, a lot of what you are doing is resetting properties that should be static.
That's all I can see anyways. |
|
AntiFiterJoin Date: 2009-05-14 Post Count: 12290 |
"If you are constantly using the same CFrames, you should make them a variable. That way you don't need to create one every 1/60 of a second (approx)."
I could do that, but still, if you're moving around it won't make a difference.
"As well, you can try to make the math functions local."
I tried making Asin a variable, but it didn't help too much.
"Is there a reason you need to set constantly the Neck.C1? I wouldn't think so.
In fact, a lot of what you are doing is resetting properties that should be static."
It glitches the head if you don't. I'll try to make it work without it though. |
|
|
This isn't really a fix but you can try to squeeze performance out of the program
local cf = CFrame.new
local angles = CFrame.Angles
local asin = math.asin
local c1Default = cf()
local c0Default = cf(0, 1.5, 0)
-- set variables for the neck and left/right arm
neck.C1 = c1Default
neck.C0 = c0Default * angles(asin((LocalMouse.Hit.p - LocalMouse.Origin.p).unit.y), 0, 0) |
|