Question by
Sounds-Wonderful · Aug 28, 2019 at 09:55 PM ·
c#instantiatehingejoint
On creating a rope to not get lost in caves
My goal is for the player(first person controller) to attach a rope to himself that he mounts to the entry of a cave and then the further he moves the more rope he lets go. To find the way back, by following the rope.
How could I create such a rope with unity, such that
It bends around edges
I count how long it is to make it end at some point
When the player goes back, he collects the rope and therefore can go another way with the amount of rope he collected.
Now I started with this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Seil : MonoBehaviour
{
public GameObject prefab;
GameObject vorher = null;
GameObject jetzt = null;
void Start()
{
InvokeRepeating("Fallenlassen", 6.0f, 1.0f);
}
void Fallenlassen()
{
if (vorher != null)
{
jetzt = Instantiate(prefab, transform.position, Quaternion.identity);
HingeJoint joint = jetzt.AddComponent<HingeJoint>();
joint.anchor = vorher.transform.localPosition;
joint.axis = Vector3.forward;
}
else
{
jetzt = Instantiate(prefab, transform.position, Quaternion.identity);
}
vorher = jetzt;
}
void Update()
{
}
}
To use a hingejoint and form a rope by simply connecting a lot of spheres together. Try it out to see the issue, it's hard to explain.
How do I come from my script to my desired result?
Comment