Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

BongDev

8
Posts
1
Topics
2
Following
A member registered Apr 03, 2021 · View creator page →

Creator of

Recent community posts

████████╗ ██╗░░██╗ ██╗ ░█████╗░ ░█████╗░
╚══██╔══╝ ██║░░██║ ██║ ██╔══██╗ ██╔══██╗ 
░░░██║░░░ ███████║ ██║ ██║░░╚═╝ ██║░░╚═╝
░░░██║░░░ ██╔══██║ ██║ ██║░░██╗ ██║░░██╗
░░░██║░░░ ██║░░██║ ██║ ╚█████╔╝ ╚█████╔╝

Make a quit Button brrhhh

Hey amazing game

broooo

I have figured it out thanks for help

Hey synced the line renderer but giving error line renderer out of bounds when processing it in Rpc_DrawRope method

Can't figure it out!! 😰😰😰

please help me how to sync line renderer this is my code:-


using UnityEngine;

using Photon.Pun;

public class Grappling : MonoBehaviourPunCallbacks

{

    private LineRenderer lr;

    private Vector3 grapplePoint;

    public LayerMask whatIsGrappleable;

    public Transform gunTip, player;

    public Camera camera;

    private float maxDistance = 100f;

    private SpringJoint joint;

    PhotonView PV;

    

    void Awake()

    {

        lr = GetComponent<LineRenderer>();

        PV = GetComponent<PhotonView>();

    }

    void Update()

    {

        if (PV.IsMine)

        {

            if (Input.GetMouseButtonDown(1))

            {

                StartGrapple();

            }

            else if (Input.GetMouseButtonUp(1))

            {

                StopGrapple();

            }

        }

    }

    //Called after Update

    void LateUpdate()

    {

        DrawRope();

    }

    /// <summary>

    /// Call whenever we want to start a grapple

    /// </summary>

    

    void StartGrapple()

    {

        RaycastHit hit;

        if (Physics.Raycast(camera.transform.position, camera.transform.forward, out hit, maxDistance, whatIsGrappleable))

        {

            grapplePoint = hit.point;

            joint = player.gameObject.AddComponent<SpringJoint>();

            joint.autoConfigureConnectedAnchor = false;

            joint.connectedAnchor = grapplePoint;

            float distanceFromPoint = Vector3.Distance(player.position, grapplePoint);

            //The distance grapple will try to keep from grapple point. 

            joint.maxDistance = distanceFromPoint * 0.8f;

            joint.minDistance = distanceFromPoint * 0.25f;

            //Adjust these values to fit your game.

            joint.spring = 4.5f;

            joint.damper = 7f;

            joint.massScale = 4.5f;

            lr.positionCount = 2;

            currentGrapplePosition = gunTip.position;

        }

    }

    /// <summary>

    /// Call whenever we want to stop a grapple

    /// </summary>

    

    void StopGrapple()

    {

        lr.positionCount = 0;

        Destroy(joint);

    }

    private Vector3 currentGrapplePosition;

    

    void DrawRope()

    {

        

            PV.RPC("RPC_DrawRope", RpcTarget.AllBuffered);

    }

    public bool IsGrappling()

    {

        return joint != null;

    }

    public Vector3 GetGrapplePoint()

    {

        return grapplePoint;

    }

    [PunRPC]

    void RPC_DrawRope()

    {

        //If not grappling, dont' draw rope

        if (!joint) return;

        currentGrapplePosition = Vector3.Lerp(currentGrapplePosition, grapplePoint, Time.deltaTime * 8f);

        lr.SetPosition(0, gunTip.position);

        lr.SetPosition(1, currentGrapplePosition);

    }

}

████████╗  ██╗░░██╗  ██╗  ░█████╗░  ░█████╗░ ╚══██╔══╝  ██║░░██║  ██║  ██╔══██╗  ██╔══██╗ ░░░██║░░░  ███████║  ██║  ██║░░╚═╝  ██║░░╚═╝ ░░░██║░░░  ██╔══██║  ██║  ██║░░██╗  ██║░░██╗ ░░░██║░░░  ██║░░██║  ██║  ╚█████╔╝  ╚█████╔╝ ░░░╚═╝░░░  ╚═╝░░╚═╝  ╚═╝  ░╚════╝░  ░╚════╝