英文:
How do I weld two anchored parts together?
问题
我创建了一个障碍关卡,其中有掉落的石头,玩家必须在它们再次落到地面之前通过它们。但如果他们被石头的底部击中,他们会死亡。如果我在石头上使用触摸事件,玩家也会在从侧面触摸它时死亡。所以我在底部添加了一个非常薄的部分,如果他们触摸到它,他们会死亡。唯一的问题是,这个薄部分不会随着大石头移动。请注意,我的大石头和薄部分都是锚定的。
我尝试过使用WeldConstraints,Welds,Motor6Ds,Attachments等等。但没有什么真正有效的。是我太蠢了还是应该完全换一种方法?
或者我应该只使用一个模型?
Darrian想要看看我的代码,所以这是我的代码(我正在使用TweenService):
coroutine.resume(coroutine.create(function()
while true do
task.wait(math.random(0.4,0.6))
local FallTween = TweenService:Create(
Stone,
TweenInfo.new(1.5, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false),
{
['Position'] = Vector3.new(Stone.Position.X, Stone.Position.Y - moveDistance, Stone.Position.Z)
}
)
FallTween:Play()
FallTween.Completed:Wait()
task.wait(1)
local GoUpTween = TweenService:Create(
Stone,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false),
{
['Position'] = Vector3.new(Stone.Position.X, Stone.Position.Y + moveDistance, Stone.Position.Z)
}
)
GoUpTween:Play()
GoUpTween.Completed:Wait()
end
end))
(顺便说一句,对于那些说我不应该使用图像链接的人,Stack Overflow不允许我嵌入图像)
英文:
I made an obby stage where there are falling stones and the player has to get through them before they fall on the ground again. But if they get hit from the bottom face of the rock, they will die. If I would use a touch event on the stone, the player would also die if they touched it from the side. So I added a really thin part on the bottom face and if they touch that they will die. The only problem is, that the thin part doesn't move with the big rock. Notice that both my big rock and my thin part are anchored
This is normal
This is when the part is moving in-game
I've tried using WeldConstraints, Welds, Motor6Ds, Attachments etc. But nothing really worked. Am I too dumb or should I do something completely different?
Or should I just use a model?
Darrian wanted to see my code so here it is (I'm using TweenService):
coroutine.resume(coroutine.create(function()
while true do
task.wait(math.random(0.4,0.6))
local FallTween = TweenService:Create(
Stone,
TweenInfo.new(1.5, Enum.EasingStyle.Quint, Enum.EasingDirection.In, 0, false),
{
['Position'] = Vector3.new(Stone.Position.X, Stone.Position.Y - moveDistance, Stone.Position.Z)
}
)
FallTween:Play()
FallTween.Completed:Wait()
task.wait(1)
local GoUpTween = TweenService:Create(
Stone,
TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.In, 0, false),
{
['Position'] = Vector3.new(Stone.Position.X, Stone.Position.Y + moveDistance, Stone.Position.Z)
}
)
GoUpTween:Play()
GoUpTween.Completed:Wait()
end
end))
(By the way for these people who say I shouldn't use links for images, Stack Overflow doesn't allow me to embed images)
答案1
得分: 1
你可以对具有焊接和其他物理部件的零件进行缓动,但由于 Tween 服务不是基于物理的转换,连接的部件将不会随之移动。
我在 DevForum 上找到了一个论坛帖子,解释了这个问题以及他们的解决方案。
https://devforum.roblox.com/t/tweening-welded-objects/323897
就我个人而言,我会编辑我的代码,同时缓动两个部件。为此,我会计算 Tween 移动的距离,并在同一个脚本中将相同的 Tween 应用于两个部件。
由于 TweenService
不是基于物理的,应该更多地用作纯粹用于视觉目的的动画移动,我不建议在这个障碍物中使用缓动,因为当缓动动画播放时,触摸事件可能无法按预期工作。
或者,您可以将 RodConstraint
用作一种类似活塞的装置,其中您可以编写一个脚本来更改其延伸的长度。这意味着您可以简单地将另一个部件焊接上,而不会遇到相同的问题。
英文:
You can tween parts that have welds and other physics parts however as Tween Service isn't a physics based translation the connected parts will not move with it.
I found a forum post on the DevForum explaining this with their solution.
https://devforum.roblox.com/t/tweening-welded-objects/323897
Personally I would edit my code to tween both parts simultaneously. To do this I would work out the distance the Tween travels and apply the same tween to both parts within the same script.
Because the TweenService
is not physics based and should be used more as a animation based movement for purely visual purposes I wouldn't recommend using tweening for this obby obstacle as the touch event might not work as intended when the tween animation plays.
Alternatively you could use a RodConstraint
as a sort of piston where you have a script that changes the length at which it is extended. This would mean you could simply weld the other part and not have the same problem
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论