I want the part to be looking at the ball while being tweened to the new position but I can only make it move or make it look at the ball not both a the same time how do I make it
while true do
wait(5)
goal.CFrame = (Zone.CFrame * CFrame.new(
(math.random() - 0.5) * Zone.Size.X,
(math.random() - 0.5) * Zone.Size.Y,
(math.random() - 0.5) * Zone.Size.Z))
CFrame.lookAt(pos, workspace.GoalSystem.ball.Position) --supposed to make the part look at the ball
local tween = TweenService:Create(part, info, goal)
tween:Play()
end
From what I am gathering with your problem, you want to Tween a model and make the model look at a part while it is tweening right?
Would this work?
Every time the code loops through your function, you run a for loop.
Make a final end goal.
In the for loop, define a new position for a part (not your model, just an obscure part that will go where you want your model to go).
The new location should only be a fraction of the distance between your start position and the end position (this can probably be achieved through the lerp() function). The new position should involve the CFrame.LookAt to make it look at your desired object.
After defining a location for this part, Tween the part to this new location.
Add a new script that sets the model’s CFrame to the part’s CFrame using the RunService.
In summary: instead of tweening the model directly from point A to point B, you are going to Tween the model from point A to different checkpoints along the way to Point B. The model will not always look at your desired object, but the room for error will be much smaller.
Now is about the time you should look at linear interpolation.
LERP.
a number from 0-1 and given that is your alpha, you should store your initial start cframe, initial alpha which is 0 or 1.
If you wish to impliment a easingStyle tweenService can let you. link
Here is a rough example.
local startAlpha = 0
local startCF = Zone.CFrame
local endCF = goal.CFrame??
while true do
--// ofc subject to client fps throttles which you can account for yourself by using runservice or deltatime etc anything that can smoothly get your value from 0 to 1 without client fps throttles affecting it.
local newAlpha += 0.1 --// you need to replace this with a stable one.
local newCF = startCF:Lerp(endCF, tweenService:GetValue(fillwithyourinfo here)).Position
part.CFrame = CFrame.lookat(newCF --// position, lookatPos)
end
You may want to consider working with positions but I think this is fine.
This is a rough draft and will DEFINITELY not work with syntax currently. You need to look into some things to properly understand how you can well get your newAlpha from 0 to 1 stable and in the speed you want which I image will be / time
Now I wrote that I think setting a startTick = tick() and desiredTime = x
and then newAlpha = tick() - startTick / desiredTime
should work just fine but heyho.
hope this helped a little bit.
edit;
One benefit of this, it will also account for if your lookat pos changes at all just a thought.
after getting the FInalDestination the egg doesnt start the tween and waits until the second time the loop starts then it doesnt stop at 25% and 50% of the destination it just goes straight to 75% then the egg (part) goes back to the previous position and again to 75% of the destination until the loop starts again
i tried a few ways but its the same every time
local part = script.Parent
local TweenService = game:GetService("TweenService")
local Zone = game.Workspace.Zone
local pos = part.Position
local targetCF = part.CFrame
local FinalDestination = workspace.FinalDestination
local info = TweenInfo.new(
2,
Enum.EasingStyle.Linear,
Enum.EasingDirection.Out,
0, -- Repitions
false,
0
)
local goal = {}
local goal2 = {}
while true do
wait(5)
FinalDestination.CFrame = (Zone.CFrame * CFrame.new(
(math.random() - 0.5) * Zone.Size.X,
(math.random() - 0.5) * Zone.Size.Y,
(math.random() - 0.5) * Zone.Size.Z))
local tween = TweenService:Create(part, info, goal)
local tween2 = TweenService:Create(part, info, goal2)
function LookAtBall()
goal2.CFrame = CFrame.lookAt(pos, workspace.GoalSystem.ball.Position)
tween2:Play()
task.wait(2)
end
goal.CFrame = part.CFrame:Lerp(FinalDestination.CFrame, 0.25)
tween:Play()
task.wait(2)
LookAtBall()
goal.CFrame = part.CFrame:Lerp(FinalDestination.CFrame, 0.5)
tween:Play()
task.wait(2)
LookAtBall()
goal.CFrame = part.CFrame:Lerp(FinalDestination.CFrame, 0.75)
tween:Play()
task.wait(2)
LookAtBall()
end
I have idea:
What about tweening position of some part, and setting cframe of model to local newcf = CFrame.new(somepart.Position)×CFrame.lookAt(blablabla) btw srry for ×, im on mobile and i dont have right character
instead of doing each move as its own line of code, try putting it in a for-loop. That way the model cannot continue until the loop is done. Something like:
for i = 1, 4, 1 do --tells game to loop 4 times
goal.CFrame = part.CFrame:Lerp(FinalDestination.CFrame, (i/4)) --CFrame math but in terms of i
tween:Play()
task.wait(2)
end
basically this code will do what you have already done, just with the restriction of not being able to continue until after the 2 second wait. I hope this helps.