Hey, how can i make player drive up smoothly on the side walk, i don't have that much 3D experience, i know there's a wheel collider but i couldn't get that to work at all (player would fall over way too easy, and it's not really fitting for the project to lock rotation, also suspension would just lunch the player in the air)
#How can i make player drive up smoothly on the side walk
1 messages · Page 1 of 1 (latest)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
// Speed of the car in meters per second
[SerializeField]
float speed = 10.0f;
// Maximum speed of the car in meters per second
[SerializeField]
float maxSpeed = 20.0f;
// Rotation speed of the car in degrees per second
[SerializeField]
float rotationSpeed = 90.0f;
[SerializeField]
GameObject[] movementEffect;
// Reference to the car's rigidbody component
Rigidbody rb;
void Start()
{
// Get the rigidbody component
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
if (rb.velocity.y > -0.5f && rb.velocity.y < 0.5f)
{
Movement();
}
}
void Movement()
{
// Get input from the horizontal axis
float horizontalInput = Input.GetAxis("Horizontal");
// Calculate the current speed of the car
float currentSpeed = rb.velocity.magnitude;
// Rotate the car based on the speed and input
rb.MoveRotation(rb.rotation * Quaternion.Euler(0, rotationSpeed * horizontalInput * Time.deltaTime * currentSpeed / maxSpeed, 0));
// Get input from the vertical axis
float verticalInput = Input.GetAxis("Vertical");
// If the player is moving forward, spawn a particle effect
foreach (GameObject particle in movementEffect)
{
particle.SetActive(currentSpeed > 1.0f);
}
// If the current speed is less than the maximum speed, apply a force in the forward direction based on the input
if (currentSpeed < maxSpeed)
{
rb.AddForce(transform.forward * speed * verticalInput);
}
}
}
```\
Uhh
Why... are you using a Box Collider on a wheel...
You can either use a Mesh Collider with the cylinder mesh assigned to it, or just use a really thin Capsule Collider
Well it's fixed now, i had figured the mesh collider, but i also had to set rigidbody to continous dynamic to make this work at all
I am new to 3D, had to learn about the mesh collider
they don't have circle colliders in 2d?
maybe he's trying to optimizing stuff
You don’t optimize by giving a wheel a box collider 
There is circle collider in 2D
There is no cylinder collider in 3D
There used to be btw, but they removed it 
😳 you can always make one from blender