- Home /
Needing Help on How to Interact With Screws/Screwdriver,How to Make a Screw/Bolt Interactable with a Screwdriver
Hello,
I am new to Unity and was trying for my first project to interact with objects. The example that I am wanting to do is having a sheet of metal with 4 holes that I have already made. But with the 4 holes I would like to have a screwdriver interact with the screws and being able to actually screw into the sheet of metal. I just don't know where to go from here honestly. I don't know what type of script I need to make, what components to add to the screws, what video's to watch or to learn, any help on this would be much appreciated. Here is the model of screws as well that I'm trying to use for project:
Screws: https://assetstore.unity.com/packages/3d/props/industrial/bolt-and-nut-2763 Tools: https://assetstore.unity.com/packages/3d/workplace-tools-86242
TLDR: Trying to interact with screws/screwdriver don't know how, help please.
Thank You!
$$anonymous$$y reaction is that the goal is more toward the intermediate level and probably shouldn't be your first project, but then I must acknowledge that is highly relative to one's own motivation, previous experience and knowledge.
"... being able to actually screw into the sheet of metal."
$$anonymous$$y reading of this implies a physics oriented simulation of a real world act, and despite what real time physics engines do well, this kind of simulation can stretch those capabilities to a point that you'll have several $$anonymous$$or issues which combine to confuse the subject. The interaction of the screw's thread with the metal, for example, is likely not to work well, if for no other reason (which I must assume without having the model to exa$$anonymous$$e) that threads are not typically modeled for physics, just for appearance. Threads would create what is known as non-convex (concave) geometry which the physics engine is particularly incapable of perfor$$anonymous$$g. Assu$$anonymous$$g that is handled with script, the second issue is the Phillips opening on the head of the screw is also a non-convex geometry, though that can be modeled in physics as a collection of convex parts fitted together, that is not typically done for something is physically small and trivial. That would mean there's nothing for the screw driver to fit into, from the physics engine viewpoint, without that specialized modeling. If that modeling were done, the issue becomes a user interface complication of aligning the screwdriver tip (which is in the intermediate level of control scripting). All of this can be overcome, so I'm not saying it is impossible, but it does represent the kinds of things game programmers don't actually do for "actually" driving a bolt. A game programmer would 'simulate' that act through scripting where the physics engine isn't used, but the objects are manipulated in script to look like the act is being performed (and one would argue that it is) as an appearance only, not as a physics simulation.
Game physics are like a puppet show. When it looks right, it is right, even if it isn't accurate as an engineering simulation would be.
Hello,
Thank you for replying to this I really appreciate all of the feedback/help I can get! I'm sorry but, would you be able to explain it to me so I can understand it better? I'm glad you went into depth in this it shows that you took the time to type this out for me which I appreciate! But I'm really new to unity and just don't know where to start the process of trying to screw something into say a wall. The project I'm trying to work on is a training simulation on how to build a pump. So I would like to start small with trying to put a screw on a screwdriver to then screw it into a part. Would you be able to help on where I should go from here or what actions I should try? Thank you for all the help/feedback I honestly appreciate you taking your time in helping me it means a lot!
I'm heading out to an appointment at the moment, so it may be much later before I can pick up to continue. We'll discuss the finer points then.
No worries, hope everything goes well. Thanks again for the help, very much appreciated!
Answer by JVene · Oct 03, 2018 at 05:04 PM
A full tutorial is beyond the scope of a post here, but a few main points should suffice to get things moving.
Given the caveats in my comment that this is not likely a good choice for a beginner, start with just the screw.
Place the wall in an orientation where it is aligned with the world axis (the wall should not be rotated relative to the axis, the wall should be one of the axis aligned planes). This is necessary so as to simplify the rotation of the screw. Next, place and align the screw to a hole into which is should be driven, with the tip of the screw touching the hole.
Attach a script to the screw object which will operate the screw's motion without physics. Search for how to use Time.deltaTime. Create a float representing the rotation of the screw (starts out zero). Using the editor, figure out which of the 3 localRotation values rotate the screw in the direction of a screw turning the same way as being driven by a screwdriver (which comes later). Fashion code in the Update function of the script (not FixedUpdate since this isn't using physics), so that the screw's rotation (the float) increases gradually over time (using Time.deltaTime), and apply that using the eulerAngles property of the screw's localRotation. This should make the screw turn. Adjust so the speed makes some sense.
The screw will turn without end like a wheel or gear at this point. Next, add to the script a motion of the localPosition property of the screw so that it moves slowly toward the wall while the screw is turning. Create a float for this speed like the one used for rotation of the screw. Adjust these two values, the speed for turning the screw and the speed for driving the screw toward the wall until the appearance is reasonable.
Observe and test for the point at which the screw is fully "in", so you can then sense this in Update and stop the rotation and the drive motions - the endpoint of screwing the screw into the wall.
Once completed, you can place and align the screwdriver so it is positioned appropriately relative to the screw, then apply the same rotations to the screwdriver. This can be done by temporarily making the screwdriver a child of the screw, or you can duplicate the Update function to independently control the screwdriver and the screw. Either way, you'll need to fashion a way to start this 'animation by code' and then after the screw stops, remove the screwdriver (which may also require you to 'deparent' the screwdriver from the screw if that approach is used.
I realize that for a beginner this may be more than makes sense at first. This reflects the fact that this is more than a beginner should consider.
Now, I should point out that while you've said you want to start out small, I think you'll need to start out smaller. I've attempted to incorporate that notion in the means by which the screw is made to operate (separating rotation from driving). There are lots of ways to implement this concept, including making animations in Blender or 3DS Max, using them for the motions involved instead of coding.