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

1 Like

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.

2 Likes

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

1 Like

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.

1 Like

Sorry for bumping an older post, but did you ever figure it out? What did you end up doing? I’m having the same dilemma. Thanks!

1 Like

I didn’t figure it out, I just made it so you click the attachment on either end of the constraint to select it

Woah, how’d you do that? did you also give the attachment an invisible part as a hitbox? Also, can I try out the game? :grin:

I did give it an invisible hitbox, just a sphere positioned on top of the attachment’s WorldCFrame

also the game is privated because it’s still in development

Wow, it must be quite the project then! How could I add a reminder to myself to try it out when it comes out, I’m super curious! Thanks!

yea for sure. The game is called tower creator rescripted, it’s a remake that’s been in development for a very very long time now. Look up “Boring Tower Studio” or “Tower Creator” on roblox for the group or the game

Alright, thank you :smiley:

1 Like