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)
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)
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
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?
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.
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.
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
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