Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by TopofMorning · Feb 16, 2020 at 10:48 AM · unity 5beginnercar gamecar physicswheel colliders

Problem with cars in Unity 5

This is pretty much my first time making something like this so please be easy, these questions also might be obvious, but i haven't been able to find answers. (all these questions are based around the same car, in the same project/scene).
.
Question #1: I am making my first game heavily inspired by Brackeys when he had to make a game based on the topic "Small World". It's basically a car that drives around a sphere in the sky right now, but i'm having a lot of problems already.
(Its not letting me upload an image so this a link to Pasteboard https://pasteboard.co/IUVWjsg.png) .
So in my scene there, if i start driving my car it goes very slowly and after i made the mass of the car go up from 100 to 1500, and the the wheels go up from 20 to 1000 it was actually driveable, but even after i did that it was still very slow, so i bumped it up even more, and it just stopped going forwards (btw im not able to scale anything down, don't ask). This question leads me on to my next one.
.
Question #2: So I tried driving around the very slow car and after i reached the bottom, it didn't want to move anymore, even though I have gravity attractor and body scripts, it just stopped, but it works again after i manually dragged it back up to the top of the sphere.
Gravity Attractor script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class GravityAttractor : MonoBehaviour
 {
 
     public float gravity = -3700f;
 
     public void Attract(Transform body)
     {
         Vector3 targetDir = (body.position - transform.position).normalized;
         Vector3 bodyUp = body.up;
 
         body.rotation = Quaternion.FromToRotation(bodyUp, targetDir) * body.rotation;
         body.GetComponent<Rigidbody>().AddForce(targetDir * gravity);
     }
 
 }
 

Gravity Body script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent (typeof (Rigidbody))]
 public class GravityBody : MonoBehaviour
 {
 
     GravityAttractor planet;
 
     void Awake()
     {
         planet = GameObject.FindGameObjectWithTag("Planet").GetComponent<GravityAttractor>();
         GetComponent<Rigidbody>().useGravity = false;
         GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
     }
 
     void FixedUpdate()
     {
         planet.Attract(transform);
     }
 
 }
 

.
Question #3 (Final): When I am turning my car it works but doesnt at the same time (the wheels turn and everything) but instead of actually turning, it just drifts of to the right or left and i would like to know how to fix that. Here is my script for the car (you will probably need it to answer the other questions as well. Full Car script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerController : MonoBehaviour
 {
 
     public void GetInput()
     {
         m_horizontalInput = Input.GetAxis("Horizontal");
         m_verticalInput = Input.GetAxis("Vertical");
     }
 
     private void Steer()
     {
         m_steeringAngle = maxSteerAngle * m_horizontalInput;
         wheelFRW.steerAngle = m_steeringAngle;
         wheelFLW.steerAngle = m_steeringAngle;
     }
 
     private void Accelerate()
     {
         wheelFRW.motorTorque = m_verticalInput * motorForce;
         wheelFLW.motorTorque = m_verticalInput * motorForce;
     }
 
     private void UpdateWheelPoses()
     {
         UpdateWheelPose(wheelFRW, wheelFRT);
         UpdateWheelPose(wheelFLW, wheelFLT);
         UpdateWheelPose(wheelBRW, wheelBRT);
         UpdateWheelPose(wheelBLW, wheelBLT);
     }
 
     private void UpdateWheelPose(WheelCollider _collider, Transform _transform)
     {
         Vector3 _pos = _transform.position;
         Quaternion _quat = _transform.rotation;
 
         _collider.GetWorldPose(out _pos, out _quat);
 
         _quat = _quat * Quaternion.Euler(new Vector3(0, -90, 0));
         print(_quat);
 
         _transform.position = _pos;
         _transform.rotation = _quat;
     }
 
     private void FixedUpdate()
     {
         GetInput();
         Steer();
         Accelerate();
         UpdateWheelPoses();
     }
 
     private float m_horizontalInput;
     private float m_verticalInput;
     private float m_steeringAngle;
 
     public WheelCollider wheelFRW, wheelFLW;
     public WheelCollider wheelBRW, wheelBLW;
     public Transform wheelFRT, wheelFLT;
     public Transform wheelBRT, wheelBLT;
     public float maxSteerAngle = 30;
     public float motorForce = 50;
 
 }

In-Game options that came out of the script:https://pasteboard.co/IUU9lhO.png .
I'm sorry if this was annoying, but i'm very stupid. I would love any answers for any of these questions if you could. Sorry about the pasteboard links, it wouldnt let me upload an image. (also ask me if there is any more pictures or information from my project you need to be able to help me) Thank You!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

226 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems with cars in Unity 5 0 Answers

How to automatically stop car when fuel ends up ? 2 Answers

Strange Wheel Colliders 0 Answers

Car Physics 0 Answers

How to make traction control for car? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges