Hello! I am working on a train system and one of the features for this system is the ability for trains to couple. I currently have a system that works, its a bit rubbish but I’m making improvements to it but one thing I also want to change is how it looks when it couples.
I have a touched event connected in the coupler on the unit the player is in, at then it’ll create the rigid constraint and attach the 2 couplers together therefore making a coupled train but that doesn’t look too good. So I’m wanting to make the coupler more animatedish like the videos below. I also have a part the size of the coupler that’s invisible to act as the coupler with attachments for the rigid constraint and the constraint to let the coupler turn left and right when the train turns on the tracks.
I can’t provide a video of what it looks like when it couples right now because I’m recoding the train system and the couplers aren’t really working with the upgraded chassis I’m using so its disabled.
I want that smooth sort of push, pull bounce effect.
Instead of making a touched event, I would check the position of the couplers and initiate the “coupling” when they are close to each other. This should be much cleaner and optimized.
Next up, for your smooth coupling effect, I would use one of the many constraints. For example, you could use a RopeConstraint, if you find it appropriate, and tween its length to something big, and slowly make it to 0 or something a bit bigger so they are correctly connected and wont act weirdly.
With this method you will get a smooth connection, and not an instant one.
Also, make sure to anchor one of the carriages during the animation and unanchor right after the tween finishes for something even more like the videos you attached.
Thank you for your reply, I’m not sure how would I find the closest other coupler?
If possible could you provide me with some sort of template or instructions?
Another thing I was thinking is I could use a Prismatic Constraint or even a Spring Constraint and that could push the coupler in a bit then pull out. I did only want it to depend on how far the train goes into the coupler I didn’t really want it to be once the trains close it automatically does it.
Would I also need to add suspension to the train for the train to sort of bounce?
You can use a Raycast to detect when a given position and distance intersects another part, you should find a way of not having to call it frequently since it can be an expensive operation
Regarding the physics side, I’ve never understood the new constraint system outside of the more basic ones
Would it be better to stick to the touched event or using raycast (performance wise)?
The touched event is only connected when there’s a player seated in the train and gets disconnect when the player exits the train.
I’ll wait a bit to see what other people say about it. I did watch a video on how to scharfenberg couplers work and there’s some kind of dampener to absorb the forces of the trains.