We can't give snake movement to 3D car
Hello, we've been working on a problem for about 3 weeks and couldn't find a solution. This is the game we want to make
https://www.youtube.com/watch?v=nkUqtcLrmag
However, the problem we face is this;
https://drive.google.com/file/d/1fvqeA-1qYzedIr2JS9mKLT5gXrmFpsTf/view?usp=sharing
As the car rotates, breaks occur, I guess every rig rotates on its own axis.
Solutions we tried;
-increase the polygon of the car -Increasing the number of rigs and putting them in different places -Painting with Weight Painting -Physical body
We rig the car in blender. Blender also does not have a problem with its stretching, but when it comes to Unity, it does so.
The solutions we think are;
-if each rig rotates from the same pivot point the problem can be solved but we don't know how to do it.
-Can it be done with shaders?
We would be very happy if you could help :)
This is the source code we used
void Start() {
for (int i = 0; i < listBones.Count; i++)
{
GameObject newPivot = new GameObject();
newPivot.transform.parent = transform;
newPivot.transform.position = pivot.transform.position;
listPivots.Add(newPivot);
listBones[i].transform.parent = newPivot.transform;
}
listBones.Clear();
for (int i = 0; i < listPivots.Count; i++)
{
listBones.Add(listPivots[i].transform);
}
bone1 = listBones[0].gameObject;
}
void Move() { if (listBones.Count <= 0) return;
float mouseX = Input.GetAxis("Mouse X");
float mouseY = Input.GetAxis("Mouse Y");
if (Input.touchCount > 0)
{
mouseX = Input.touches[0].deltaPosition.x;
mouseY = Input.touches[0].deltaPosition.y;
}
if (Input.GetAxis("Horizontal") != 0)
listBones[0].Rotate(Vector3.up * 5 * Time.deltaTime * mouseX);
for (int i = 1; i < listBones.Count; i++)
{
curBodyPart = listBones[i];
prevBodyPart = listBones[i - 1];
dis = Vector3.Distance(prevBodyPart.position, curBodyPart.position);
Vector3 newPos = prevBodyPart.position;
newPos.y = listBones[0].position.y;
newPos.z -= 1f;
float T = 0;
T = 45 * Time.deltaTime;
if (T > 0.3f)
T = 0.3f;
//curBodyPart.position = Vector3.Slerp(curBodyPart.position, newPos, T);
curBodyPart.rotation = Quaternion.Slerp(curBodyPart.rotation, prevBodyPart.rotation, T);
}
transform.Translate(-bone1.transform.right * Time.deltaTime * speed);
//bone1.transform.Translate(-bone1.transform.up * mouseX * Time.deltaTime * speed);
//transform.Translate(transform.right * mouseX * Time.deltaTime * speed);
bone1.transform.Rotate(Vector3.up * mouseX * Time.deltaTime * sensitiviy * 15);
//Limits
if (transform.position.x >= 3.5f) transform.position = new Vector3(3.5f, transform.position.y, transform.position.z);
else if (transform.position.x <= -3.5f) transform.position = new Vector3(-3.5f, transform.position.y, transform.position.z);
}
Your answer
Follow this Question
Related Questions
Make an object follow another object's path (Snake game) 0 Answers
Importing blender model with rigid body 0 Answers
Car steering on a Rigidbody (Mario Kart) 0 Answers
What is the best way to calculate the performance stats of a car in a racing game? 1 Answer
Car not shooting like bullet properly 2 Answers