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

Why am I going slower when I turn my camera up (custom marble character)?

Asked by
NordicM 77
3 years ago
Edited 3 years ago

Hello.

I am trying to make a game like the games where you are a marble. I have gotten the controls to work but when I pan my camera up so I see the marble from on top, I go slower left and right. I think this has to do with the camera's lookVector if I'm not wrong.

game:GetService("RunService").RenderStepped:Connect(function()
    if canMove.Value == true then
        bodyVelocity.AngularVelocity = Vector3.new() --// The bodyVelocity is a BodyAngularVelocity
        local direction = controlModule:GetMoveVector()
        if direction.X > 0 then
            bodyVelocity.AngularVelocity = bodyVelocity.AngularVelocity + direction.X * speed * camera.CFrame.LookVector
        end
        if direction.X < 0 then
            bodyVelocity.AngularVelocity = bodyVelocity.AngularVelocity + direction.X * speed * camera.CFrame.LookVector
        end
        if direction.Z > 0 then
            bodyVelocity.AngularVelocity = bodyVelocity.AngularVelocity + direction.Z * speed * camera.CFrame.RightVector
        end
        if direction.Z < 0 then
            bodyVelocity.AngularVelocity = bodyVelocity.AngularVelocity + direction.Z * speed * camera.CFrame.RightVector
        end
    else
        bodyVelocity.AngularVelocity = Vector3.new()
    end
end)

Any helps appreciated and try not to rewrite the whole code. If you know a solution just say what I have done wrong/have to do.

Thanks.

EDIT: If you want to see the problem for yourself (Here)

1 answer

Log in to vote
0
Answered by
NordicM 77
3 years ago

I found a much easier way of doing this. I will walk through my progress if people want to know. So the humanoid has a property called MoveDirection. It will say which direction the roblox character will move to. If you put a humanoid in the custom character (which you probably have) you can go into the humanoid and get the move direction from it and apply it to the bodyVelocity (I am now using the normal BodyVelocity because it's easier to use it if you are adding a jump mechanic).

local speed = 20

game:GetService("RunService"):RenderStepped:Connect(function()
    bodyVelocity.Velocity = hum.MoveDirection * speed
end)
Ad

Answer this question