How to make model move?

I have this code:

local t = 6.5;
local point = workspace:WaitForChild("Point")
local hrp = workspace:WaitForChild("Spawner"):WaitForChild("BoxBody")
local bball = workspace:WaitForChild("Box");

local function createBox(count)
	for i = 1, count, 1 do
		local g = Vector3.new(0, -workspace:WaitForChild("Gravity").Value, 0);
		local x0 = hrp.CFrame * Vector3.new(0, 5, 5)

		-- calculate the v0 needed to reach mouse.Hit.p
		local v0 = (point.Position - x0 - 0.5*g*t*t)/t;

		-- have the ball travel that path
		local c = bball:Clone();
		
		c.Velocity = v0;
		c.CFrame = CFrame.new(x0);
		c.CanCollide = true;
		c.Parent = game.Workspace;
		
		task.spawn(function()
			task.wait(15)
			local explosion = Instance.new("Explosion")
			explosion.BlastPressure = 500000
			explosion.ExplosionType = Enum.ExplosionType.Craters
			explosion.BlastRadius = 20
			explosion.Position = c.Position
			explosion.Parent = workspace
			
			c:Destroy()
		end)
		
		task.wait(0.1)
	end
end

while task.wait(5) do
	createBox(10)
end

This code moves a part from one position to another in a parabolic way using .Velocity. However how would I move a model instead of a part with .Velocity? Also do you know any other alternatives to .Velocity?

1 Like

Also I forgot to mention that I have tried :ApplyImpulse and VectorForces but .Velocity is the only one that works accurately for me

1 Like

weld the entire model to the part you’re trying to move

2 Likes

I wanna say try using PrimaryPart for the Model, hopefully using that it can work with your function?

Try setting the Models PrimaryPart, unanchor the whole model, weld it, and then use velocity on the Primary Part.

1 Like

I would recommend either welding all the parts of the model to a single part (Primary Part) or just using the PivotTo function for models

I have done everything you guys have said but now I have another problem:


The models aren’t spawning in the red part, which is the spawner.

Here is my code:

local t = 6.5;
local point = workspace:WaitForChild("Point")
local hrp = workspace:WaitForChild("Spawner"):WaitForChild("BoxBody")
local bball = game:GetService("ServerStorage"):WaitForChild("Box");

local function createBox(count)
	for i = 1, count, 1 do
		local g = Vector3.new(0, -workspace:WaitForChild("Gravity").Value, 0);
		local x0 = hrp.CFrame * Vector3.new(0, 5, 5)
		print(x0)
		-- calculate the v0 needed to reach mouse.Hit.p
		local v0 = (point.Position - x0 - 0.5*g*t*t)/t;

		-- have the ball travel that path
		local a = bball:Clone();
		local c = a:WaitForChild("BoxBody")
		
		
		c.CFrame = CFrame.new(x0);
		c.Velocity = v0;
		print(c.CFrame)
		c.CanCollide = true;
		a.Parent = game.Workspace;
		
		task.spawn(function()
			task.wait(15)
			local explosion = Instance.new("Explosion")
			explosion.BlastPressure = 500000
			explosion.ExplosionType = Enum.ExplosionType.Craters
			explosion.BlastRadius = 20
			explosion.Position = c.Position
			explosion.Parent = workspace
			
			c:Destroy()
		end)
		
		task.wait(0.1)
	end
end

while task.wait(5) do
	createBox(1)
end

When I print the Cframe, it is correct however the model still doesn’t go to that Cframe.

Turns out that the problem was I had to set the Model’s parent to be workspace before applying velocity.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.