Making a part move forward but made it Move on Negative Z-Axis instead

Hello devs, i think i got trouble here.

I’m trying to make a part moves forward by multiplying their CFrame like in the script below.

local Speed = 0.1

Remote.OnClientEvent:Connect(function(ball)
	while ball do
		ball.CFrame *= CFrame.new(0,0,-1)
		task.wait(Speed)
	end
end)

But weirdly, the “Ball” moves on Negative Z-Axis Direction.
I newly get this problem after studio updates.
I tried to look up for solution but found no one discussing about this problem.

Here’s the result of the script anyways:

The script itself runs on the Client-Side (to makesure the movement was smooth enough)

Thank you

3 Likes

It is moving on the Negative Z-Axis because the “-1” there is on the Z-Axis:

CFrame.new(x,y,z) -- x is the X-Axis, y is the Y-Axis, and z is the Z-Axis

If you want to move it forwards, I’d recommend putting the minus one on the X-Axis.

Make sure the part’s orientation is correct, given that if you put it 90 degrees, it may move at another direction, instead.

3 Likes

Is it kind of the new update or something?
Because i never experienced this before…

I tried to change the CFrame.new(0,0,-1) to CFrame.new(1,0,0)

But it ends up moving in Positive X-Axis Direction

3 Likes

I’d also recommend removing the while loop and implementing a Heartbeat event, like that:

local Speed = .1
local RS = game:GetService("RunService")
local Heartbeat = RS.Heartbeat

Remote.OnClientEvent:Connect(function(ball)
    local connection = Heartbeat:Connect(function(delta)
         if not ball then connection:Disconnect() return end
         ball.CFrame = ball.CFrame * CFrame.new(-1,0,0)
         task.wait(Speed)
    end)
end)
3 Likes

It moves in Positive X-Axis because you’re simply putting 1 at the X-Axis, and one is a positive number.

2 Likes

If you want to make it smoother, you can remove the task.wait, and implement delta there, like that:

local Speed = 2
ball.CFrame = ball.CFrame * CFrame.new(-Speed * delta, 0, 0)

if it is too slow, you can only increase the ball’s speed.

I’d recommend, additionally, to use Vector3 instead of CFrame, to update the position directly, as CFrame is used mainly when you want to change a basepart’s position, orientation, and a lot others

5 Likes

Thanks! , but my main problem is why do my “Ball” is going on 1 direction instead of going forward according to it’s rotation?

I’ve been using the statements like part.CFrame *= CFrame.new(0,0,-n) to move parts forward.

Well, you did recommend me using Vector3 to update the position (Making it move forward according to it’s rotation). Do you mind giving me the example codes?

1 Like

If it was working moving parts with negative Z-Axis values, it means the orientation of the part was convenient to it. If the orientation of the part is at 360, the X-Axis would be the opposite of it, so it would move back.

You can use Vector3 like that:

ball.Position += Vector3.new(1,0,0)

When you move a part using CFrame, it’s coordinate would differ according to its orientation/rotation. It is because the CFrame is the local coordinate of the part, while Vector3 is the global coordinate, so it doesn’t matter if it is 100 degrees rotated.

1 Like

I tried to follow this discussion’s solution

It works before the studio’s update. Is this studio’s bug or indeedly mistake in the scripting?

1 Like

Could you share the part’s orientation? Also, why are you trying to move the part’s position according to the orientation, if it doesn’t matter the value of its rotation?

There’s script inside the player character. So everytime this “skill” is played, it clones the ball that was parented on ServerStorage and state their CFrame in front of the players

Ball.CFrame = HumanoidRootPart.CFrame * CFrame.new(0,0,-15)
(This code is running as i expected)

And after a few delay, it fires the remote to play the Ball Moving Animation.
The Moving script is the one i gave you a few moment ago

1 Like

Alright. But is it obligatory for you to use CFrame instead of Vector? If you’re messing up with the basepart’s orientation, then using CFrame would be convenient, but if you’re not, then you could try using Vector3. You want it to be relative to its orientation?

Alright, so. When you multiply two CFrames, it translates it.
Here’s how you make a part go in the direction it is facing:
(Script under the part)

local function move(studs)
    script.Parent:PivotTo(script.Parent:GetPivot() + script.Parent:GetPivot().LookVector * studs)
end

move(5) --move 5 studs forward
1 Like

Yes, i want it to move relatively to its orientation
I wonder how to move a part forwardly using the Vector3 anyways

Why using PivotTo? Why not CFrame or Vector3?

CFrame already moves relatively to the basepart’s orientation, that’s why the ball was moving strangely.

Parts are PVInstances. Functions related to Pivot all use CFrame. It is essentially CFrame functions.

1 Like

I guess use LookVector then? So it’d move to where the part’s looking at

1 Like

You mean’t this?
ball.CFrame += ball.CFrame.LookVector * n

I tried that one, and the ball is still moving awkwardly