- Home /
Chain in 2D top down perspective.
So I have my android game, it's called Racers, and I want to add a new weapon. The weapon should be a rope or chain with maybe like a heavy steel ball on the end. The chain is fixed on the racer. I want the the player can pull the ball with the chain over the field. A bit like in Skull Chainz (https://chaoclypse.itch.io/skullchainz) To get you a closer look what I mean, here's my game: https://play.google.com/store/apps/details?id=com.HenrichProductions.Racer So how do I do that? I tried it with hinge joints, but they fly apart and due to their weight they pull the Racer back. Another problem is that the Racer is constantly rotating and the chain keeps stiff and rotates like a stick with the racer, but I want it to swing. Please help me :(
You should probably add multiple hinge joints for every link in the chain, and edit the breakForce to be unbreakable
Even with 4 hinge joints and break force to Infinity nothing changes. The chain links continue flying apart.
Answer by DerLasseHenrich · Aug 10, 2018 at 09:32 PM
So I found the issue. To not pull the Racer back, I've set the masses of the links to 0.001. That's why the chain kept stiff. So now all the masses of my links ( except of the last one which is heavier ) are set to 1. The mass of the Racer is set to the Highest, so it isn't affected by the chain. I don't know why it flew apart, but now it doesn't do that anymore, so... it's working.
Hey! I'm still struggling with making a ball and chain mechanic on my game, $$anonymous$$d sharing your code for reference? $$anonymous$$y code looks like this right now, the main problem is that the distance between the anchor and connected anchor just keeps changing. using System.Collections; using System.Collections.Generic; using UnityEngine;
public class DragandDrop : $$anonymous$$onoBehaviour {
private bool selected;
public HingeJoint2D joint;
void Start()
{
HingeJoint2D joint = GetComponent<HingeJoint2D>();
}
void Update()
{
if (selected == true)
{
Vector2 cursorPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3 mouseLocalPosition = transform.InverseTransformPoint(cursorPos);
joint.connectedAnchor = cursorPos;
joint.anchor = mouseLocalPosition;
}
Debug.Log(Input.mousePosition);
if (Input.Get$$anonymous$$ouseButtonUp(0))
{
selected = false;
}
}
void On$$anonymous$$ouseOver()
{
if (Input.Get$$anonymous$$ouseButtonDown(0))
{
selected = true;
}
}
}
Hey! For that purpose I used a Distance Joint ins$$anonymous$$d of a Hinge Joint. Let me know if that works!
Your answer
Follow this Question
Related Questions
2D Top down physics with ground (slippery floor...) 1 Answer
Custom Cursor hidden behind my UI 2 Answers
Need a critique of my weather code (top-down 2D) 0 Answers
How to access a tile? 1 Answer
2D custom sort axis not working at all 2 Answers