FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • Tethering Two GameObjects Together By a Rope Through CodePayasoPrince
    What I need assistance with: I need to create a rope connecting two GameObjects together at runtime through code. One end will be connected to Transform _pointA and the other will be connected to Transform _pointB. I've divided the rope up into segments of GameObjects that have a Hinge joint 2D & a Rigidbody 2D. Each segment uses it's parent's Rigidbody 2D as the Connected Rigid Body. Then I set positions on the LineRenderer to match the segment positions so that I can later use rope ma
     

Tethering Two GameObjects Together By a Rope Through Code

What I need assistance with:

  • I need to create a rope connecting two GameObjects together at runtime through code.

  • One end will be connected to Transform _pointA and the other will be connected to Transform _pointB.

  • I've divided the rope up into segments of GameObjects that have a Hinge joint 2D & a Rigidbody 2D.

  • Each segment uses it's parent's Rigidbody 2D as the Connected Rigid Body.

  • Then I set positions on the LineRenderer to match the segment positions so that I can later use rope material to make it looks nicer.


Issue:

  • When the rope is initially created, it immediately falls straight down creating a vertical rope rather than a horizontal rope, even though the final rope segment is positioned at _pointB with the correct parent's Rigidbody connected.
  • After a few moments, the rope falls apart without moving any positions manually.
  • Additionally, if the rope is manually moved, it immediately falls apart.
  • To demonstrate the issue, I added a circle sprite to each segment GameObject in the rope.

enter image description hereenter image description here

  • Which causes the line to look like this:

enter image description here


Here's an example of how I would like it to look when moving the two objects further/closer:

enter image description here


The Code I'm Using:

public class Rope: MonoBehaviour
{

    [SerializeField] private LineRenderer _line;
    [SerializeField, Range(2, 50)] int _segmentCount = 2;

    [SerializeField] private Transform _pointA;
    [SerializeField] private Transform _pointB;

    [SerializeField] HingeJoint2D _hingeJoint;

    public Transform[] segments;
    private void Start()
    {
        GenerateRope();
    }
    // Update is called once per frame
    void Update()
    {
        SetEndOfRopePositions();
        SetLinePoints();
    }

    private void SetEndOfRopePositions()
    {
        segments[0].position = _pointA.position;
        segments[segments.Length - 1].position = _pointB.position;
    }

    private void SetLinePoints()
    {
        _line.positionCount = segments.Length;

        for (int i = 0; i < segments.Length; i++)
        {
            _line.SetPosition(i, segments[i].position);
        }
    }
    private Vector2 GetSegmentPosition(int segmentIndex)
    {
        Vector2 posA = _pointA.position;
        Vector2 posB = _pointB.position;

        float fraction = 1f / (float)_segmentCount;
        return Vector2.Lerp(posA, posB, fraction * segmentIndex);
    }
    void GenerateRope()
    {
        segments = new Transform[_segmentCount];

        for (int i = 0; i < _segmentCount; i++)
        {

            var currJoint = Instantiate(_hingeJoint, GetSegmentPosition(i), Quaternion.identity, this.transform);
            segments[i] = currJoint.transform;

            if (i > 0) // Not first hinge
            {
                int prevIndex = i - 1;
                currJoint.connectedBody = segments[prevIndex].GetComponent<Rigidbody2D>();
            }
        }
    }

}

Inspector for Rope + Segment GameObjects before running the game: enter image description here

  • ✇Kotaku
  • Mortal Kombat 1 Mod Recreates The Drake Vs. Kendrick BeefKenneth Shepard
    The dust seems to have mostly settled on the Drake vs. Kendrick Lamar rap beef (for now), but the musical back and forth between the two hip-hop titans has imprinted itself on pop culture. That imprint includes video game mods, as a Mortal Kombat 1 fan has recently recreated both rappers in the game to pit them…Read more...
     

Mortal Kombat 1 Mod Recreates The Drake Vs. Kendrick Beef

17. Květen 2024 v 20:47

The dust seems to have mostly settled on the Drake vs. Kendrick Lamar rap beef (for now), but the musical back and forth between the two hip-hop titans has imprinted itself on pop culture. That imprint includes video game mods, as a Mortal Kombat 1 fan has recently recreated both rappers in the game to pit them…

Read more...

  • ✇Android Police
  • Tile Pro vs. Chipolo One: Which is the better smart tracker?Gaurav Shukla
    The Tile Pro and the Chipolo One are two of the most popular smart tags that are platform-agnostic, which means they are compatible with Android and iOS devices. The two can achieve this by relying on their own tag networks to locate your belongings rather than leveraging Apples Find My or Googles Find My Device networks. You will find a lot of other similarities between the two smart trackers. However, which of the two is most beneficial? Lets find out.
     

Tile Pro vs. Chipolo One: Which is the better smart tracker?

12. Květen 2024 v 20:00

The Tile Pro and the Chipolo One are two of the most popular smart tags that are platform-agnostic, which means they are compatible with Android and iOS devices. The two can achieve this by relying on their own tag networks to locate your belongings rather than leveraging Apples Find My or Googles Find My Device networks. You will find a lot of other similarities between the two smart trackers. However, which of the two is most beneficial? Lets find out.

Does Tile support Google's Find My Device network?

3. Květen 2024 v 15:00

Google recently performed a mass roll-out of a feature iPhones have sported for years. After nearly a year of waiting, its Find My Device network has finally gone live, enlisting the help of Android users worldwide to track lost or stolen items.

❌
❌