Beispiel #1
0
 private void Start()
 {
     player       = FindObjectOfType <Player>();
     ropeRenderer = GetComponentInChildren <RopeRenderer>();
     target       = GetComponentInChildren <Target>();
     ropeRenderer.gameObject.SetActive(false);
     emitter = GetComponent <FMODUnity.StudioEventEmitter>();
 }
Beispiel #2
0
    // Helper function to generate the bridge
    private void GenerateBridge()
    {
        // Get the world position of the center of the two anchors
        Vector3 localAnchor = transform.TransformPoint(new Vector3(0f, 0.5f, 0.5f));
        Vector3 otherAnchor = _otherAnchor.transform.TransformPoint(new Vector3(0f, 0.5f, -0.5f));

        // Get the distance between the two points
        float distance = Vector3.Distance(localAnchor, otherAnchor);

        // Calculate the length of the plank (assuming the unscaled prefab has a length of 1 unity unit)
        float plankLength = Vector3.Distance(_plankPrefab.transform.TransformPoint(new Vector3(0f, 0.5f, 0.5f)), _plankPrefab.transform.TransformPoint(new Vector3(0f, 0.5f, -0.5f)));

        // Calculate how many planks we would need to not have too big gaps in between (gap size only for a fully horizontal bridge, not after it starts to hang)
        int plankCount = Mathf.FloorToInt((distance - _maxGapDistance) / (plankLength + _maxGapDistance));

        // Calculate the gap distance based on the number of planks we will use
        float gapDistance = ((distance - (plankCount * plankLength)) / (plankCount + 1f));

        // Check if we need to add planks at all
        if (1 < plankCount)
        {
            // Keep track of the current and previous planks (or anchors), so that we can add the joint connections
            GameObject currentPlank  = gameObject;
            GameObject previousPlank = null;

            // Until we have added the required number of planks
            for (int i = 0; i < plankCount; ++i)
            {
                // Calculate the center position of the next plank
                // There's a gaps and planks alternating, and for the last plank we only go half it's length
                Vector3 position = Vector3.Lerp(localAnchor, otherAnchor, ((gapDistance + plankLength) * (i + 1) - (plankLength / 2f)) / distance);

                // Create a new plank
                previousPlank = currentPlank;
                currentPlank  = Instantiate <GameObject>(_plankPrefab, position, transform.rotation);

                // Add the connection between the new and the previous parts
                AddSpringConnections(previousPlank, currentPlank.GetComponent <Rigidbody>());

                // If a rope prefab is set, add a rope renderer component
                if (null != _ropePrefab)
                {
                    RopeRenderer ropeRenderer = previousPlank.AddComponent <RopeRenderer>();
                    ropeRenderer.RopePrefab = _ropePrefab;
                }
            }

            // Connect the last plank to the other anchor
            AddSpringConnections(currentPlank, _otherAnchor);

            // If a rope prefab is set, add a rope renderer component
            if (null != _ropePrefab)
            {
                RopeRenderer ropeRenderer = currentPlank.AddComponent <RopeRenderer>();
                ropeRenderer.RopePrefab = _ropePrefab;
            }
        }
    }
 private void Awake()
 {
     _tagManager   = GameObject.Find("TagManager").GetComponent <TagManager>();
     _uiManager    = GameObject.Find("UIManager").GetComponent <UIManager>();
     _audioManager = GameObject.Find("AudioManager").GetComponent <AudioManager>();
     _animator     = GameObject.Find("Player").GetComponent <Animator>();
     _ropeRenderer = GetComponent <RopeRenderer>();
     _animator.SetBool("Pull", false);
 }
Beispiel #4
0
 public void CreateRope(float pRopeLength, Vector2 pBasePosition, LineRenderer pLineRenderer)
 {
     mRopeLength = pRopeLength;
     mNumberOfHinges = Mathf.CeilToInt(mRopeLength * 4);
     mRopeSegments = new GameObject[mNumberOfHinges];
     mLengthOfEachSegment = GetLengthOfEachSegment();
     mLineRenderer = pLineRenderer;
     CreateRopeSegments (pBasePosition);
     AttachRopeSegments ();
     mRopeRenderer = new RopeRenderer (mLineRenderer, mRopeSegments);
 }
Beispiel #5
0
 public void Grab(RopeSegment rope)
 {
     if (rope.ropeRenderer != grabbedRope)
     {
         grabbedRope = rope.ropeRenderer;
         //Ragdoll the character
         //Move hips to the rope position
         //Attach the joint to the hips
         _isOnRope = true;
         if (!ragdoll.IsRagdolled)
         {
             ragdoll.Ragdoll(true, Vector3.zero);
         }
         Attach(rope);
         OnRopegrab?.Invoke(rope);
         Physics.SyncTransforms();
     }
 }
Beispiel #6
0
    public override void OnInspectorGUI()
    {
        DrawDefaultInspector();
        ropeRenderer = target as RopeRenderer;

        // Used for taking screenshots
        if (!Application.isPlaying)
        {
            if (GUILayout.Button("Update Spline"))
            {
                ropeRenderer.UpdateControlPoints();
            }

            if (GUILayout.Button("Update Render"))
            {
                ropeRenderer.UpdateRopeRender();
            }
        }
    }
 private void Awake()
 {
     ropeJointManager = GetComponent <RopeJointManager>();
     ropeRenderer     = GetComponentInChildren <RopeRenderer>();
     audioSource      = GetComponent <AudioSource>();
 }
Beispiel #8
0
 void Awake()
 {
     ropeRenderer = GetComponent <RopeRenderer>();
 }
Beispiel #9
0
 void Awake()
 {
     fishinglineRender = GetComponent <RopeRenderer>();
 }
 private void Awake()
 {
     _ropeRenderer  = GetComponent <RopeRenderer>();
     _contactPoints = new Vector3[2];
 }
Beispiel #11
0
 public void Zero()
 {
     grabbedRope = null;
 }