New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

How to point CFrame's UpVector towards a point to have the bottom of a part facing a direction?

Asked by 11 days ago
Edited 11 days ago

Hi there, so, after about a day of trying to figure this out, my math seems to be incorrect, or I am doing something wrong. I am creating a "Phaser" rifle, where a cone is shot from the tip of the rifle, and expands out ("I can do that part, that's easy.) The trouble is, the bottom of the cone has to expand towards whatever direction the mouse clicks. My current solution is using a position constraint, and two attachments, one at the tip of the cone and one on a part called "Tip" Either my math is wrong, or the constraint is not working as I expected.

The code to make the cone point its bottom towards the mouse local target = conVals.Aim.Value local oldCF = tool.WideBeam.CFrame local upVec = target * -1 local nLook = upVec:Cross(oldCF.LookVector) local nRigh = nLook:Cross(upVec) local nCFra = CFrame.fromMatrix(oldCF.p, nLook,upVec,nRigh) tool.WideBeam.CFrame = nCFra

Is my math wrong? Or is there somethign else going on? Might I add, all that ends up happening is my character moves out of control when I activate the tool.

Answer this question