#okay I ve been trying to figure out how

1 messages · Page 1 of 1 (latest)

hollow gate
#

Looks good to me. Assigning them in the Inspector should work. Can you post the error-message that unity prints? Are you sure you are using this exact component you made a screenshot here and don't have another Player Movement Component attached somewhere?

quasi reef
#

I'm basicly trying to make a grappler thing

hollow gate
#

ahh okay you get another message now, I thought you still got "no object assigned"

quasi reef
#

ah yes

#

I got the error message solved

#

but it still doesn't work how I want it to work

hollow gate
#

never worked with distance joints sry :/

quasi reef
#

oh okay

keen shell
#

Hm... looking at the docs real quick

#

The Distance Joint cannot connect to the GameObject that holds the component (itself basically). Since the joint is placed on the player, you need to make sure the target (connectedBody and/or connectedAnchor) must be the target of your grappler, the object you want to fasten the grapple to.

#

attachedRigidbody is the rigidbody the joint is attached to (here the player)

quasi reef
keen shell
#

Not really worked with joints etc before, but the gist is to raycast from the player towards the crosshair (which I guess you have) and if it hits something: check if it is a point you want the player to be able to grapple to.

quasi reef
#

I'm literally just following this tutorial, and get the same exact error

#

I changed my code to this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    private Vector3 _mousePos;
    private Camera _camera;

    private bool _check;

    private DistanceJoint2D _distanceJoint;

    private LineRenderer _lineRenderer;

    private Vector3 _tempPos;

    // Start is called before the first frame update
    void Start()
    {
        _camera = Camera.main;
        _distanceJoint = GetComponent<DistanceJoint2D>();
        _lineRenderer = GetComponent<LineRenderer>();
        _distanceJoint.enabled = false;
        _check = true;
        _lineRenderer.positionCount = 0;
    }

    // Update is called once per frame
    void Update()
    {
        GetMousePos();
        if (Input.GetMouseButtonDown(0) && _check)
        {
            _distanceJoint.enabled = true;
            _distanceJoint.connectedAnchor = _mousePos;
            _lineRenderer.positionCount = 2;
            _tempPos = _mousePos;
            _check = false;
        }
        else if (Input.GetMouseButtonDown(0))
        {
            _distanceJoint.enabled = false;
            _check = true;
            _lineRenderer.positionCount = 0;
        }
        DrawLine();
    }

    private void DrawLine()
    {
        if (_lineRenderer.positionCount <=0) return;
        _lineRenderer.SetPosition(0, transform.position);
        _lineRenderer.SetPosition(1, _tempPos);
    }
    
    private void GetMousePos()
    {
        _mousePos = _camera.ScreenToWorldPoint(Input.mousePosition);
    }
}
#

like wtf is wrong

keen shell
#

the "cannot connect to itself" error?

quasi reef
#

I also tried just copying code from the internet on a grappling hook but I always get the error