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

How do you use Vector3 to move an object a non-axis direction with a certain force?

Asked by 5 years ago
Edited 5 years ago

I'm trying to make a boat to move using Vector3 and there isn't very much info in regards to using NormalId. Is there a way to make this work or is there a better solution?

local UIS = game:GetService("UserInputService")
local seat = script.Parent
local gyro = seat.BodyGyro
local pos = seat.BodyPosition
local vel = seat.BodyVelocity
local occupant = seat.Occupant
local IsOccupied = false

UIS.InputBegan:connect(function(input)
    if IsOccupied == true then
        if input.KeyCode == Enum.KeyCode.W then
            seat.Anchored = false
            vel.Velocity = Vector3.FromNormalId(Enum.NormalId.Front) -- These make it move very slowly

        elseif input.KeyCode == Enum.KeyCode.A then
            seat.Anchored = false
            vel.Velocity = Vector3.FromNormalId(Enum.NormalId.Left)

        elseif input.KeyCode == Enum.KeyCode.S then
                seat.Anchored = false
            vel.Velocity = Vector3.FromNormalId(Enum.NormalId.Back)

        elseif input.KeyCode == Enum.KeyCode.D then
            seat.Anchored = false
        vel.Velocity = Vector3.FromNormalId(Enum.NormalId.Right)

        end     
    end
end)

Thanks for the help!

0
Is your script a localscript or server script? User#19524 175 — 5y
0
It is a server script, when I tried porting it to a local script it didn't work at all CoosBuckett 10 — 5y
0
UserInputService doesn’t exist on the server. You should handle user input on LocalScripts only. User#19524 175 — 5y
0
Alright, however the problem here is that the boat won't move very far. Do you know how NormalId works? CoosBuckett 10 — 5y
View all comments (3 more)
0
Gonna base this from "http://wiki.roblox.com/index.php?title=API:Vector3" but all you're doing is applying a unit vector(vector w/ magnitude 1) to the velocity. In effect, you're just making it move at a snail's pace. To make it move faster, consider multiplying the vector by a constant like 100 or something. ScrewDeath 153 — 5y
0
To give you a direction on how to address your non-axis direction problem, consider using InputEnd (not sure of the actual name) for UserInput Service. Register all keys being held down w/ InputBegan and recalculate the velocity based on the keys being held. Use InputEnd to get rid of the key being held down, and recalculate the velocity. ScrewDeath 153 — 5y
0
Alright, thanks for the help! CoosBuckett 10 — 5y

Answer this question