Greetings fellow coders! So I have recently started a new first-person game. I have so far followed Brackey’s first-person movement tutorial, then went on to make a grappling gun so I can attach and move to “things”. This is my code:
using UnityEngine;
public class hook : MonoBehaviour {
public Transform cam;
private RaycastHit hit;
public bool attached = false;
public float momentum;
public float speed;
public float step;
void Start()
{
}
void Update()
{
if (Input.GetButtonDown("Fire1")){
if (Physics.Raycast(cam.position, cam.forward, out hit)){
attached = true;
}
}
if (attached){
momentum += Time.deltaTime * speed;
step = momentum * Time.deltaTime;
transform.position = Vector3.MoveTowards(transform.position, hit.point, step);
}
}
}
for some reason when I try running the scene and “use” the grappling gun I lose the ability to jump and I don’t end up grappling to the cube. Not sure what to do so consulting with you fellow experts out there! Thanks in advance ! P.S If you need more code or info I can provide it