I’d basically like to shoot ropes at a specific angle and attach to any items with the tag (Wall) and stay hooked until you let go, at the same time allowing you to swing from them and automatically reel in? I am a basic beginner so I will not understand most things about Unity and programming, just basic stuff. Any help would be appreciated. (Thank You)
Just a theoretical idea:
You could start a Raycast from your player to wherever you are pointing to, if it hits something (your Wall) then save that point and start rotating your player around that point by using a variable “speed” that increases if the player’s Y-Position moves down and decreases if the Y-Position moves up, until a specific angle or height is reached where the speed slowly stops and then the player start’s swinging back again.
Maybe something like: (this code is written here in the answer, so it might something be wrong and you will need to make some adjustments, but maybe it helps you to start your code).
[SerializeField] LayerMask layerMaskWall; //Set this in inspector to "Wall"
RaycastHit hit;
Vector3 direction; // Whatever direction you wan't to point to.
float maxDistance = 10.0f; // How far the rope should go.
Vector3 ropePoint = Vector3.zero;
float speed;
float lastYPos;
if (Physics.Raycast(player.transform.position, direction, out hit, maxDistance, layerMaskWall)
{
if (hit.transform.tag == "Wall") // If you wan't an extra check for specific things
{
ropePoint = hit.point;
}
}
// And then to swing around that point:
// The Axis thats used for the rotation determines what kind of game you make. In my case i say you make something like a Jump'n'Run game like Super Mario.
if (ropePoint != Vector3.zero)
{
player.transform.RotateAround(ropePoint, Vector3.forward, speed * Time.deltaTime);
//Then we need something to increase / decrease the speed:
if (lastYPos > player.transform.position.y)
{
// Increase the speed
speed += 1 * Time.deltaTime;
}
else if (lastYPos < player.transform.position.y)
{
speed -= 1 * Time.deltaTime;
}
lastYPos = player.transform.position.y;
}
To end the rope swing, just set the ropePoint to Vector3.zero again.
Also this code doesn’t include anything to stop the rope yet, if you reach the other side.