Hey guys,
How would I go about orienting a model so that a specific part in the model faces a target position? If I use model:PivotTo(CFrame.lookat(model’s position, target)), the primarypart faces the target position, rather than the specific part i want.
Use the parts cframe.Position for the lookat, then to get differnent points on the part you can add a cframe to that parts cf, e.g a corner would be adding half the parts size, just got to change what you add to get different part. CFrame is all relative which is why we do it this way if you just add to position you can end up with misalignment
I think you misunderstand, I dont mean points on a part like corners, but as in parts within a model. Secondly, I want the model to remain positioned with its primarypart at the origin, but have it oriented in such a way that a specific part within the model is pointed toward the target
I’m not gonna do all the cframe stuff but if it were me I’d cframe the target part independently of the gun model, making it face the desired direction and then cframing it to be at the front of the gun. then use weldconstraint to weld it to the gun. this would have to be done in a loop though. i think the problem is youre using model:PivotTo which works off the base part of the model, so I’m not sure how you would expect it to know how to cframe specifically that other part
why do you want this part to face a target? with gun you should just rotate your projectile and effects to the target location…? from that point…
to do this just use something like this to get the CFrame with rotation from that parts position
local newLookAtCFrame = CFrame.lookAt(part.Position,target.Position)
you can then use this to position the bullet at the parts current location with that orientation just by setting the bullet.CFrame
also can use the rotation by itself with newLookAtCFrame.Rotation
you can then give the bullet forward velocity or something else by using this cframes lookvector with newLookAtCFrame.LookVector