Whats the best way to make softbody phyiscs
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 https://www.youtube.com/watch?v=tTdKEJpX2HI&t=29s 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);
}
}
Answer by canslp · Jul 27, 2020 at 12:30 PM
your instinct to make a bunch of rigidbodys with joints is probably the way to go, seems like there's just some kind of organizational hangup. you could also try having raycasts apply force if they detect a surface nearby, like car tire suspension style
How i could solve the movement script to work with though? I achived the jiggly behaviour but the movement no...
Your answer
Follow this Question
Related Questions
How do I model a piston? 0 Answers
Spring Joint Grappling Hook help please 0 Answers
Unity 3D Balloons tied together (Physics) 0 Answers
Trying to simulate a "Slime" like soft body ball. 0 Answers
How can I use a Spring Joint to pull two objects together? 0 Answers