#How can i make player drive up smoothly on the side walk

1 messages · Page 1 of 1 (latest)

vast salmon
#

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)

#
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);
        }
    }
}
```\
spiral light
#

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

vast salmon
#

I am new to 3D, had to learn about the mesh collider

raw lintel
#

they don't have circle colliders in 2d?

young sluice
spiral light
spiral light
#

There used to be btw, but they removed it butwhy

young sluice
#

😳 you can always make one from blender