Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I make my part move? (Specifics in Q).

Vague title because I need to be quite specific and can't think how to word the title properly.

I'm moving a part when I press the WASD keys. When I press W I want it to move forward, when I press A I want it to move left, etc.

Just considering W and A for now to keep things simpler, how do I make my part move forward and turn properly. I have tried to make it move forward using a body velocity with the Velocity property equal to the part's lookvector as so:

script.Parent.BodyVelocity.Velocity = script.Parent.CFrame.lookVector

This works to a point, but doesn't actually go entirely in a straight line drawn from the part, it seems to veer off for some reason. Not sure if anyone knows why this is or how to avoid it?

As for turning, I'm struggling with figuring out how to make it turn. Presumably, if I can make it turn properly, the forward force will be enough to make it move and turn. I am trying to get it to turn using BodyGryo but am struggling with what CFrame value to actually give it.

Considering turning left, how should I come up with a value for a left turn relative to CFrame.lookVector of the main part?

2 comments

0

I think you should try using Enum.new for the wasd keys and use Vector3 for the part that will make it move, good luck with the script..

0

lookVector is a Vector3...

1 answer

--EX1
speed = -- put speed here
script.Parent.CFrame=script.Parent.CFrame+(script.Parent.CFrame.lookVector*speed)
--EX2
speed = -- put speed here
script.Parent.CFrame=script.Parent.CFrame+(script.Parent.CFrame.lookVector*(speed* -1))

Here is a simple script to move a object forward at a certain speed. As greatneil said, use Enum.New to register imputs, put i dont agree with using Vector3.

My idea for you is to use the code in EX1 for W, Code in EX2 for S.

For A and D, use Cframe.Angles to turn the object.

I hope this helped :)

This discussion is preserved as it was. New answers, comments, and votes are closed.