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

Math not working for generating models, help??? [SOLVED]

SOLUTION: This is quite long, so I thought I'd include the solution here. Basically, instead of rotation, we use the look vector as a multiplier. Script:

local newPos = Vector3.new()
local LV = template.Hitbox.CFrame.LookVector
	
newPos = pos + Vector3.new(LV.X * (template.Hitbox.Size.X) + padding, (template.Hitbox.Size.Y / 2), LV.Z * (template.Hitbox.Size.Z) + padding)

EDIT: I've played around with look vectors, however, with a rotation of 0,0,0, the models all generate one on top of the other. My experimental script:

	local newPos = Vector3.new()
	local LV = template.Hitbox.CFrame.LookVector
	if LV.X ~= 0 then
		newPos = pos + Vector3.new((template.Hitbox.Size.X / 2) + padding, (template.Hitbox.Size.Y / 2), 0)
	else
		newPos = pos + Vector3.new(0 + padding, (template.Hitbox.Size.Y / 2), 0)
	end
	
	print(LV)
	
	if LV.X ~= 0 then
		newPos = pos + Vector3.new(0, (template.Hitbox.Size.Y / 2), (template.Hitbox.Size.X / 2) + padding)
	else
		newPos = pos + Vector3.new(0, (template.Hitbox.Size.Y / 2), 0 + padding)
	end

I think this would be better as rot would not be relied on, instead the model's direction. Could somebody fix this script ^^ to make it work? Now, the script down below seems obsolete.

So, I'm making a script to generate models. I currently have it to where I input a position and rotation, and it generates some models for an obby. I need it to dynamically update ,. However, my math seems to have failed me. Here is the equation I use to update the position, and I do this once before placing the model, and once after. My equation is such:

local newPos = pos + Vector3.new((template.Hitbox.Size.X / 2) + padding, (template.Hitbox.Size.Y), (template.Hitbox.Size.Z / 2) + padding)

I would do that once, then move the model:

model:SetPrimaryPartCFrame(CFrame.new(position) * CFrame.Angles(math.rad(rotation.X), math.rad(rotation.Y), math.rad(rotation.Z)))

Then do that again.

I should probably show you what's wrong. Here's a rotation of 0, 0, 0.

As you can see, It's super glitched. Instead of generating correctly in a straight line, they generate in a diagonal. Help?

7 comments

0

Could you show what your original model looks like?

0

Well they are randomly generated

0

Out of a folder

0

But u can see some in the imgur link.

0

I think it would be useful to see the structure of the model as well as some of the properties.

0

The only relevant things are the model itself and the hitbox: https://imgur.com/a/vg9WgxW

0

The hitbox is the size of the model, with the Y set to 1. Unless it is a vertical stage, in which case the height is the height of the stage.

1 answer

make sure you set the models primary part (in your case hitbox) this should rotate the model around the primary part

model:SetPrimaryPartCFrame(model:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(rotation.X),math.rad(rotation.Y),math.rad(rotation.Z)))

if this works please accept if not please tell me what happens

1 comment

0

make sure you take the source code not just copy

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