Hello friends! I am trying to have a jiggly behavior on my character as he rolls and jumps.
My first approach was using bones and adding spring joints, rigidbodies, sphere colliders and connect them to each other but this somewhere causes my movement script to not work. Technically what happens is the sphere collider on the model rolls out of the model’s body.
I am using this video Jelly effect on Unity3D - Efecto gelatina en Unity3D - YouTube but i lose the movement. What exactly i am trying to achive is this gif https://i.gyazo.com/a6fc870b1bf90b750f157a5090830e5a.gif
I dont want to use some assets like megafiers or whatnot so i can learn and improve a skillset and a mindset on the concept.
Here is my movement code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody rb;
//forward speed
public float forwardForce = 100f;
//left and right position definition
private float xPosition;
//Jump system
public LayerMask groundLayers;
public float jumpSpeed = 10f;
public SphereCollider col;
private void Awake()
{
rb = GetComponent<Rigidbody>();
}
// Start is called before the first frame update
void Start()
{
xPosition = rb.position.x;
col = GetComponent<SphereCollider>();
}
// Update is called once per frame
void Update()
{
//forward speed definition
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
//left and right position to key controls
Vector3 pos = rb.position;
pos.x = Mathf.MoveTowards(pos.x, xPosition, forwardForce * Time.deltaTime);
rb.position = pos;
if (Input.GetKeyUp(KeyCode.LeftArrow))
{
xPosition -= 6f;
}
if (Input.GetKeyDown(KeyCode.RightArrow))
{
xPosition += 6f;
}
//jump info
if (IsGrounded() && Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector3.up * jumpSpeed, ForceMode.Impulse);
}
//Limiting the movement to right and left as 5f (invisible wall)
transform.position = new Vector3(Mathf.Clamp(transform.position.x, -6f, 6f), transform.position.y, transform.position.z);
}
//fall info
private bool IsGrounded()
{
return Physics.CheckCapsule(col.bounds.center, new Vector3(col.bounds.center.x, col.bounds.min.y, col.bounds.center.z), col.radius * .9f, groundLayers);
}
}