Detecting When Player Clicks Constraint

For a building game I’m working on, players can place constraints between parts. Is it possible to detect when the player clicks a constraint, such as a RopeConstraint or a spring?

This is so the player can select a constraint and edit/delete the constraint

I noticed there’s no input property for clicking on constraints, and Mouse.Target doesn’t detect constraints

You could create an invisible part that can acts as an hitbox that takes up the space between the two two parts attached to the constraint. Then add a DragDetector or ClickDetector and then detect clicks on that.

1 Like

I’ve thought of that, but imagine a SpringConstraint that looks like this:

image

The invisible part as a hitbox would be huge, and also you wouldn’t be able to click between the gaps in the spring since the hitbox part takes up the entire space between the parts. Also, I’d have to constantly update the location of the part hitbox every frame if one of the parts is unanchored, since the spring would be moving around instead of staying in once place

This wouldn’t be good for performance, especially if there’s several players in game who have hundreds of constraints on their base

Yes. At rest the spring coils are parametrized by a basic vector function. You can use this to figure out where the spring is in space.

Suppose c is the number of coils: SpringConstraint.Coils
Suppose R is the radius of the coils: SpringConstraint.Radius
Suppose L is the length of the spring: SpringConstraint.CurrentLength

Then the parametrization of the string for t between 0 and 1 is something along the lines of:
p(t) = <Rcos(c * t * math.pi * 2), Rsin(c * t * math.pi * 2), L)>

Here is an example place file drawing the spring with points: tmp.rbxl (50.2 KB)

It gets a little more complex when the attached parts are not collinear, but essentially all you need to do is rotate the vector function using the angle between the two attachments.