enter image description here I made this slingshot with objects in Unity3D. I know im suppose to add components but I dont know exactly which ones. The two yellows would represent as my elastics. Keep in note i have a robot arm made on the side. My claw hand will grab the object holder and pull it back so it can shoot. I need help in
- what component should i add to them to make them like rubberband or elastic
- how attach them to my objectHolder
- how to make it shoot please help and be patient with me :( Any advice I would appreciate it. Thank you :)
CodePudding user response:
There is no magic component that will achieve what you want. You should break it down into smaller chunks.
Start with the movement of the object holder. There are different ways to achieve this. If you want to manipulate it via mouse, you can write a script that makes the objectHolder follow mouse movement while a mouse button is pressed. Once you release the mouse button you can let the object holder smoothly go back to it's start position.
For the elastic parts, I would replace the objects with LineRenderers. But also here are different ways to achieve this.
Maybe this tutorial helps you.
CodePudding user response:
attach a spring component to the dark orange round shape and set connectedAnchor to the position of where it should stretch from. You can play around with soeing and damoer to make it more or less stretchy.
I would reccomend a very high spring (spring should be about 100-1000) and mass (mass should be about 5-10) on this. The ball should have a mass of 1 or less.
You can set the Rigidbody.position to the claw's position (while it is closed) Then when it opens' it will release and launch.
For example SlingShot.cs (on the dark orange object.
[HideInInspector] public bool closedClaw = false;
[HideInInspector] public Vector3 clawPos;
Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (closedClaw)
{
rb.positon = clawPos;
}
}
And then somewhere in the script that closes the claw
SlingShot ss;
GameObject slingShot;
void Start()
{
ss = slingShot.GetComponent<SlingShot>();
}
...
if (right claw.localEulerAngles.z /*or whatever axis it rotates on*/
> 90f /*or whatever threshHold*/)
{
ss.closedClaw = true;
}
else
{
ss.closedClaw = false;
}
ss.clawPos = rightClaw.transform.position
leftClaw.transform.position;
ss.clawPos /= 2f;
All of this is untested and may have errors.
If this all works,I will come back later and do the stretchy yellow rubber bands.