|
| 31 Jan 2013 04:23 PM |
Here’s an odd little problem that hopefully will be obvious to you: I’m making a vehicle with a hatch on top. This means no anchoring, and using hinges totally messes up the look of the thing. So I’ve put in a little script that attaches the hatch to the cabin roof right next to it with a weld object, and will alter the weld settings to open and close it with a click detector. Easy, right? Right now it just raises the hatch a couple of studs’ distance, but I’ll get fancier later.
The odd part is this: When I click on the hatch, it doesn’t appear to move, but according to the object tree, its own CFrame settings, and anything else I can find, it has! It just still *looks* like it’s in the same place. To close the hatch I put the pointer above it, to where it should be, and voila, the Clicky Hand appears! Click on it, and it’s back to where it started like you’d expect.
What could cause it to move but not look like it moved?
I’ve simplified the whole thing down to a box with roof and hatch, the hatch containing a ClickDetector and script, and in the script a boolean value called IsOpened. The script is as follows:
hatch = script.Parent -- blue piece roof = hatch.Parent:FindFirstChild("roof") -- light grey piece debounce = false hingeWeld = Instance.new("Weld") hingeWeld.Part0 = hatch hingeWeld.Part1 = roof hingeWeld.C0 = hatch.CFrame:inverse() * CFrame.new(0,0,2) hingeWeld.C1 = roof.CFrame:inverse() * CFrame.new(0,0,2) hingeWeld.Parent = hatch print("hatch location begins at ", hatch.CFrame) function onClicked() if debounce == false then debounce = true if script.IsOpened.Value == false then print("open") hingeWeld.C0 = hingeWeld.C1 * CFrame.new(0,-2,4) script.IsOpened.Value = true print("hatch location is now ", hatch.CFrame) else print("close") hingeWeld.C0 = hingeWeld.C1 * CFrame.new(0,0,4) script.IsOpened.Value = false print("hatch location is now ", hatch.CFrame) end debounce = false end end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Without diagnostics and comments it’d be even smaller, of course. I left them in there because I have this up at my place right now to test it live - but the same thing happens. Running it, I see that in theory everything’s doing what I asked, but it doesn’t *look* like it. Do you have any idea why? |
|
|
| Report Abuse |
|
|
| 31 Jan 2013 04:26 PM |
| (I'm sorry about the density of the code. Normally I indent and all to make it easy to read, but it didn't take in the forum formatting.) |
|
|
| Report Abuse |
|
|
| 31 Jan 2013 04:34 PM |
| Roblox physics are awful. I could easily see why this is happening. |
|
|
| Report Abuse |
|
|
| 31 Jan 2013 11:25 PM |
| Well... I'm not sure if this would count as physics exactly. Welds sort of fall outside of that definition, don't they? Either way, it doesn't make any sense. |
|
|
| Report Abuse |
|
|
| 01 Feb 2013 04:43 PM |
SOLUTION: Well, a workaround at least. I had to do 2 things to get it to both show up and move when the C0 value was changed.
First (and strangest), I had to move the object - the box I mentioned above as the simplified stand-in for a vehicle - so that it wasn't attaching itself to the baseplate. Either putting it on something else (I discovered this by putting it on a slick metal surface to shove it around on) or lifting it a stud off the deck (so that the first thing it does is fall back down) worked.
Second, I had the script make a new Weld object each time, deleting the previous one. It could be that Welds are like CFrames in that you need to make a new one each time you want to change it. I leave that to more educated scripters to figure out.
Moving the object and re-making the weld each time takes care of the problem, and I've tried it on various things just to be sure. |
|
|
| Report Abuse |
|