I’m making an attempt to implement a grappling hook mechanic.
My grappling script is hooked up to my digicam that’s hooked up to the participant.
Generally when I attempt to grapple onto a wall, it causes jitterting when the grapSpeed
variable is 40 or extra. When it is greater than 40, it occurs virtually on a regular basis and it is extra intense.
My partitions’ rigidbodies are set to no gravity, kinematic, freeze place and rotation. My participant is not kinematic and has collision set to steady dynamic.
Right here is the grappling script:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
public class graplin : MonoBehaviour
{
public GameObject participant;
public GameObject cam;
public float hookSpeed;
Vector3 graPos;
bool canClick = true;
void FixedUpdate()
{
if(Enter.GetMouseButtonDown(0))
{
RaycastHit hit;
if(Physics.Raycast(rework.place,(rework.place - cam.rework.place).normalized,out hit))
{
graPos = hit.level;
canClick = true;
}
}
if(Enter.GetMouseButton(0) & canClick)
{
participant.GetComponent<playerControler>().enabled = false;
participant.GetComponent<Rigidbody>().useGravity = false;
participant.GetComponent<Rigidbody>().velocity = ((graPos - participant.rework.place).normalized * hookSpeed);
}
if(!Enter.GetMouseButton(0))
{
canClick = false;
participant.GetComponent<playerControler>().enabled = true;
participant.GetComponent<Rigidbody>().useGravity = true;
}
if(Enter.GetMouseButtonUp(0))
{
participant.GetComponent<Rigidbody>().velocity = Vector3.zero;
}
}
}