trying to make something look at a character, but it has an offset that isn’t working well. I’m trying to make it automatic cause this one script is running all towers.
Code:
local Cframe = CFrame.lookAt(Tower.Model.Head.Position,Target.HumanoidRootPart.Position * Vector3.new(1,0,1))
Tower:FindFirstChildWhichIsA("Model").Head.CFrame = Cframe
TweenService:Create(Tower:FindFirstChildWhichIsA("Model").Head,TweenInfo.new(.2),{CFrame = Cframe * CFrame.Angles(Tower:FindFirstChildWhichIsA("Model").Head.Orientation.X,Tower:FindFirstChildWhichIsA("Model").Head.Orientation.Y,Tower:FindFirstChildWhichIsA("Model").Head.Orientation.Z)}):Play()
Are there any errors in the output window? This code is really confusing.
astraIboy
(The Batman)
March 28, 2024, 4:48pm
#3
Do you want the offset to be in world space or in local space/object space
no errors its just rotated sideways. im trying to make it have an offset so it doesnt rotate sideways
astraIboy
(The Batman)
March 28, 2024, 4:50pm
#5
Well looks like your adding an offset to the X and Z axis from the target position
But maybe showing a screenshot of what it looks like instead of just showing the code so we can help you properly
I’m making it so it doesn’t point up. The tower defense is going to have air troops that only some can hit.
maybe define something like this?
local rotationOffset = CFrame.Angles(0, math.rad(urnumber), 0)
on “urnumber” position it to what angle you want?
astraIboy
(The Batman)
March 28, 2024, 4:52pm
#8
Could you send a screenshot of what the offset looks like currently?
Image:
@envykillie the reason why I don’t have that is because this is the script for all towers meaning if I put offset for it all will be offsetted.
astraIboy
(The Batman)
March 28, 2024, 4:55pm
#10
Also you should deconstruct the CFrame using ToEulerAngles instead of grabbing the Orientation
local TowerHead = Tower:FindFirstChildWhichIsA("Model").Head
local x,y,z = TowerHead.CFrame:ToEulerAnglesXYZ()
pardon can you explain that better? (I have smooth brain)
astraIboy
(The Batman)
March 28, 2024, 4:57pm
#12
when you use the method ToEulerAngles
what it does is it returns the approximate angles of that CFrame in that order, also you couldve just done Cframe * Head.CFrame.Rotation
astraIboy
(The Batman)
March 28, 2024, 4:58pm
#14
It’s a method on a CFrame not on the object itself
Maybe you could define another variable for urnumber
and change it when you want it to look at the character. I think it would be a longer code though
local rotationOffset = CFrame.Angles(0, math.rad(urnumber), 0)
astraIboy
(The Batman)
March 28, 2024, 4:59pm
#16
@RocketSlither
I’m guessing the cannon head is a model right, maybe try playing around with its pivot position
that work because of this is the script for ALL towers.
Fixed:
Tower:FindFirstChildWhichIsA("Model").Head.CFrame = Cframe * Tower.Model.Head.PivotOffset.Rotation
1 Like
system
(system)
Closed
April 11, 2024, 5:05pm
#19
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.