As a Roblox developer, it is currently hard to work with anchored parts that are being moved by script / being tweened, because the Touched
event does not trigger between these parts and there is no suitable alternative.
Problem Reproduction, Limitations and Impact
Consider the following code snippet as the simplest use case which reproduces the problem.
Assume that the default baseplate is present.
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, -1, true, 0 ) -- infinite tween
-- dummy part which will be tweened, positioned at 0,-5,0
local dummyPart = Instance.new("Part", workspace)
dummyPart.Position = Vector3.new(0,-5,0)
dummyPart.Anchored = true
dummyPart.CanCollide = true
dummyPart.Touched:Connect(function(touchedPart) -- action taken when touch detected
print('touch detected: ', touchedPart.Name) -- print something for testing purposes
end)
local tweenGoal = {}
tweenGoal.Position = Vector3.new(0,5,0)
TweenService:Create(dummyPart, tweenInfo, tweenGoal):Play() -- create & play tween
At first glance, we expect the Touched
event to trigger when the tweening, anchored dummy part and the anchored baseplate touch each other, but this does not happen. Discussions with the community indicate that this behaviour is the result of anchored parts which are not subject to collision detection: Touched
is fired when the physics system finds a collision, not for intersecting raw CFrame
/Position
sets.
The current workarounds are hacky in nature. One is the removal of part anchoring to trigger the event, but this causes unpredictable behaviour in the unanchored parts. Another is to keep both parts anchored, periodically checking for intersections via the GetTouchingParts()
or ray casting. The extra effort required is relatively substantial, unintuitive, and not efficient, since this technique is taking extra work to perform the work which could be expressed naturally through an Intersecting
event.
A motivation for using an Intersected
event in this scenario is the design of complex tweens which depend on the intersected part information. Simply put, in the above code, one could stop and play from a selection of tweens based on information from the intersected material. We are not interested in collision/physics but in intersection.
Proposed Solution
We propose the use of part parameter to control intersection detection, merging its behaviour with the Touched
event. Another proposal is to capture such event under a new event - an Intersecting
event in addition to Touched
.
If Roblox is able to address this issue, the community would be able to detect intersecting parts which are anchored in a more elegant way. One possible positive outcome of this would be the ability to make use of more complex and dynamic tweens using cleaner and more maintainable expressions.
(I am making this request as a result of discussion and unsatisfactory solutions proposed by the community in Part Touched event not triggered while tweening)