#okay I ve been trying to figure out how
1 messages · Page 1 of 1 (latest)
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?
nope, I have only a few components and this should work.
I'm basicly trying to make a grappler thing
ahh okay you get another message now, I thought you still got "no object assigned"
ah yes
I got the error message solved
but it still doesn't work how I want it to work
never worked with distance joints sry :/
oh okay
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)
aaaah allriiight, so if I want the target to be the connectedAnchor, then uhh how do I do that? Sorry I'm really new to coding haha
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.
How to create a grappling hook (Unity Tutorial).
Hey everyone in this video we are going to create a simple grappling hook.
I hope you find this video educational and entertaining.
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
the "cannot connect to itself" error?
well yeah
I also tried just copying code from the internet on a grappling hook but I always get the error