Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Mysterious "Force" Pushing Back Character?

Asked by 9 years ago

Weird Force

With a slightly angled birds-eye view camera of my character, whenever I make the character look at the mouse, a slight force tends to slow down my characters movement for a good couple of seconds.

This can be seen visually here:

http://www.roblox.com/games/276570398/circlesss

I've tried to reason out the issue but nothing comes to mind.


What I'm Doing

First off, I am passing in two arguments to CFrame. One is the HumanoidRootPart Position and the other is the Mouses 'hit' location

This causes the HumanoidRootPart to keep its location but turn to look at where the mouse is hitting the base.

Also, yes, the camera is slightly angled. The reason I mention is because when you keep a camera directly on top of the character, it cannot tell right from left to front to back.


Issues

1.) A mysterious force slows down the character at times

2.) Sometimes when I move the mouse, the character starts walking in a completely different direction

3.) Speed while turning gets slowed down for some odd reason


If there is a syntax error, sorry. I removed a lot of lines that didn't deal with the HumanoidRootPart.

Code

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack, false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false)
game:GetService("UserInputService").MouseIconEnabled = false
local plr = game.Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:wait()
local mouse = plr:GetMouse()
local root = chr:WaitForChild("HumanoidRootPart")
local leftLeg = chr:WaitForChild("Left Leg")
local rightLeg = chr:WaitForChild("Right Leg")
local hum = chr:FindFirstChild("Humanoid")
hum:EquipTool(plr.Backpack:WaitForChild("RealRifle"))
--

local camera = workspace.CurrentCamera
camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable;
camera.CameraSubject = hum;


local falling = false;

local mouse = plr:GetMouse()
mouse.TargetFilter = workspace.Map


hum.Changed:connect(function()
    hum.Jump = false;
end)

hum.FreeFalling:connect(function(plrFalling)
falling = plrFalling
end)

hum.Died:connect(function()
    chr = plr.CharacterAdded:wait()
    root = chr:WaitForChild("HumanoidRootPart")
    leftLeg = chr:WaitForChild("Left Leg")
    rightLeg = chr:WaitForChild("Right Leg")
    hum = chr:FindFirstChild("Humanoid")
end)



game:GetService("RunService").RenderStepped:connect(function()

root.CFrame = CFrame.new(root.Position, Vector3.new(mouse.Hit.p.X, root.Position.Y, mouse.Hit.p.Z)) 

--This is the area where I am 'rotating' the HumanoidRootPart

camera.CoordinateFrame = CFrame.new(CFrame.new(root.Position + Vector3.new(-20,45,0)).p,root.Position)

end)
0
I dunno man... sounds too spooky for me... HungryJaffer 1246 — 9y
0
honestly, I would use a bodygyro instead of CFraming. I've made a game that does basically the same function as yours (pertaining to the birds eye view and movement) and instead of cframing the follow mouse I used a BodyGyro, and it worked with no lag. HungryJaffer 1246 — 9y
0
And instead of using renderstepped, use the event of the mouse Move. It fires whenever the mouse moves. HungryJaffer 1246 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

I'm just going to try to improve your player follows mouse script.

mouse.Move:connect(function()
root.CFrame = CFrame.new(root.Position, Vector3.new(mouse.Hit.p.X, root.Position.Y, mouse.Hit.p.Z)) 
--This is the area where I am 'rotating' the HumanoidRootPart
camera.CoordinateFrame = CFrame.new(CFrame.new(root.Position + Vector3.new(-20,45,0)).p,root.Position)
end)

I used the mouse move event to stop this from running on RenderStepped. I'm not sure if this will fix the code, but it will improve it lagwise.

Ad

Answer this question