- Home /
Replace player with ragdoll
Im making a game where the player swings around like spider man. at the moment the player is just a capsule. i want to replace the capsule with a new ragdoll i made. the ragdoll works great and flops around properly but replacing the capsule with the ragdoll doesnt work and the game isnt playable. im not sure what to do to fix this or what i need to add/remove. the scripts i have are a script to let the player swing around, and a script that points the player in the direction of what they are swinging on. these are the scriipts:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GrapplingGun : MonoBehaviour
{
LineRenderer lr;
Vector3 grapplePoint;
public LayerMask whatisGrappleable;
public Transform gunTip, cameraPos, player;
float maxDistance = 200f;
private SpringJoint joint;
public static bool stopGrappleBool;
private void Awake()
{
lr = GetComponent<LineRenderer>();
StopGrapple();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartGrapple();
}
else if (Input.GetMouseButtonUp(0))
{
stopGrappleBool = true;
}
if (stopGrappleBool)
{
StopGrapple();
}
}
private void LateUpdate()
{
DrawRope();
}
void StartGrapple()
{
RaycastHit hit;
if (Physics.Raycast(cameraPos.position, cameraPos.forward, out hit, maxDistance, whatisGrappleable))
{
grapplePoint = hit.point;
joint = player.gameObject.AddComponent<SpringJoint>();
joint.autoConfigureConnectedAnchor = false;
joint.connectedAnchor = grapplePoint;
float distanceFromPoint = Vector3.Distance(player.position, grapplePoint);
joint.maxDistance = distanceFromPoint * 0.2f;
joint.minDistance = distanceFromPoint * 0.05f;
joint.spring = 10f;
joint.damper = 25f;
joint.massScale = 2f;
lr.positionCount = 2;
}
}
public void StopGrapple()
{
lr.positionCount = 0;
Destroy(joint);
stopGrappleBool = false;
}
void DrawRope()
{
if (!joint) return;
lr.SetPosition(0, gunTip.position);
lr.SetPosition(1, grapplePoint);
}
public bool IsGrappling()
{
return joint != null;
}
public Vector3 GetGrapplePoint()
{
return grapplePoint;
}
}
and the second:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RotatePlayer : MonoBehaviour
{
public GrapplingGun grappling;
private Quaternion desiredRotation;
private float rotationSpeed = 5f;
private void Update()
{
if (!grappling.IsGrappling())
{
desiredRotation = transform.parent.rotation;
}
else
{
desiredRotation = Quaternion.LookRotation(grappling.GetGrapplePoint() - transform.position);
}
transform.rotation = Quaternion.Lerp(transform.rotation, desiredRotation, Time.deltaTime * rotationSpeed);
}
}
any help would be appreciated
Comment
Are you trying to use the ragdoll only when swinging?
Your answer
![](https://koobas.hobune.stream/wayback/20220613012637im_/https://answers.unity.com/themes/thub/images/avi.jpg)