I’m basically making a game where you’re in an endless train trip, but instead of making the train move, I’m making tunnels generate and constantly tween/delete/spawn, I have achieved the generation, but now the problem is when I spawn a new tunnel in front of the previous tunnel, it sometimes spawns leaving a gap instead of being perfectly attached to the other one. Here’s a video to show what I mean :
I have checked for answers on forums but they don’t match with what im trying to achieve, what should I use to perfectly connect the spawning tunnels to the previous ones while they’re being tweened ? And how would it work ?
This is because weld constraints only work on objects affected by physics. So if you want to have them sync automatically, use a physics constraint.
Some psuedo code for that:
local direction = Vector3.new(1, 0, 0) — The direction that the next tunnel will generate. Must be 1 or -1
local rotAngle = Vector3.new(math.rad(15), 0, 0) — The angle the next tunnel will be rotated.
local tunnelComp = …
local function get_cf(oldPos)
return CFrame.new(oldPos + (direction * tunnelComp.Size)) * CFrame.Angles(rotAngle.X, rotAngle.Y, rotAngle.Z)
end
But how and which one ? If I make the tunnel moves based on physics couldn’t it be floppy ? Which one could I use to make them achieve a constant speed without bumping each other and perfectly connected with each other ? Also I’m not using weld constraint, tho I have tried but as you stated it doesnt work either. I’m currently setting the CFRame of new spawning tracks to be perfectly aligned with the previous one, but because of server delay and processing time, it makes the tween of the new track delay a little bit based on server proccess time
It is already CFramed to be perfectly connected to its previous one thought, it’s bc the server delay makes the the new spawned track delay the tween and the delay of the tween is based on server proccess time speed
Actually you can use the jigsaw method. Just put 2 attachments inside a tunnel component one for attaching other tunnel parts and another one for connecting it to the previous one. To attach a tunnel part, find the previous one and attach the new one to the connection attachments WorldPosition.
you should probably ditch the tweening and use a heartbeat loop instead, then you can use the delta time to compensate for frameloss.
runservice.Heartbeat:connect(function(delta)
print(1 * 60 * delta) -- this will compensate the number 1 and make it larger or smaller based on the delta time
end)
That fixed it, I cancel all the tweens when a new tunnel spawn so that it can perfectly position itself, then added a task.wait() then retweened everything and the small cancel time isn’t noticable by eye, thought im sure there’s a better way to implement this and im just not aware of it :3
It’s what it’s currently doing, there’s not just 1 that goes and the rest follows, each tunnels are independent and they get removed at a specific position, but it’s okay i fixed the issue by canceling each tweens once a new tunnel spawns and tweening everything back right away, althought im sure there’s a better approach but so far the rest didnt work
Yea because yours is already pre-set, if you look into the video I attached above, the tunnels are constantly tweening, and what I’m trying to achieve is connect a part to another part that is ALREADY TWEENING
Also I don’t know how i’d go about using welds because I need at least 1 part to tween, but they get deleted once they reach a point, so once the tunnel that tweens while everything else is welded to it gets destroyed, everything will be destroyed, unless i kind of use some sort of advanced way to detect all the welds, then delete them and reconnect everything but it will be a huge mess