So I wrote a script which aims to make a car object fling forwards as if the player has kicked it upon a proximity prompt trigger. The script is inside a part which is inside a car model. The car model is made of up just unanchored parts, it is strictly a model. I’ve tested this script and it works, however it only flings the car in one direction. I assume this is because it is flinging the car in the direction of the world’s Z direction, not the car’s Z direction? However I’m unsure on how to fix that.
local car = script.Parent.Parent
local prompt = script.Parent.ProximityPrompt
prompt.Triggered:Connect(function()
car.PrimaryPart.Anchored = false
car.PrimaryPart.Velocity = car.PrimaryPart.Velocity + Vector3.new(0, 10, 100)
end)
local car = script.Parent.Parent
local prompt = script.Parent.ProximityPrompt
prompt.Triggered:Connect(function()
car.PrimaryPart.Anchored = false
-- Get the local forward vector of the car
local localForward = Vector3.new(0, 0, 1) -- Assuming the car's forward direction is along the local Z axis
-- Convert the local forward vector to world space
local worldForward = car.PrimaryPart.CFrame:VectorToWorldSpace(localForward)
-- Add velocity in the direction of the local forward vector
car.PrimaryPart.Velocity = car.PrimaryPart.Velocity + (worldForward * 100) -- Adjust the magnitude as needed
end)