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 /
  • Help Room /
avatar image
0
Question by willowhyp · Mar 05, 2020 at 03:57 AM · movementwheelcolliderreverse

My vehicle is not moving backwards with WheelCollider

Hi, I am new to Unity and have a problem with reversing the car. I am running an ML agent on car to move the car through a path evading few buildings. The car works fine when moving forward and steering. But when car hits a building, I want the car to reverse a bit so that ML agent have space to turn the steering and drive the car away. But the car is not moving in reverse direction, it is just stuck with the building.

Below is my code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using MLAgents;
 
 public class CarAgent : Agent {
     public WheelCollider wheelFR;
     public WheelCollider wheelFL;
 
     public float maxMotorTorque = 150f;
     public float currentSpeed;
     public float maxSpeed = 200f;
 
     public override void AgentAction(float[] vectorAction) {
         float motorTorque = 0f;
         float maxSteerAngle = 0f;
 
         motorTorque = maxMotorTorque;
         maxSteerAngle = vectorAction[1] * 30f;
 
         PressAccelrate(motorTorque);
         SteerCar(maxSteerAngle);
     }
 
     private void PressAccelrate(float motorTorque) {
         currentSpeed = 2 * Mathf.PI * wheelFL.radius * wheelFL.rpm * 60 / 1000;
         if (currentSpeed < maxSpeed) {
             wheelFL.motorTorque = motorTorque;
             wheelFR.motorTorque = motorTorque;
         } else {
             wheelFL.motorTorque = 0;
             wheelFR.motorTorque = 0;
         }
     }
 
     private void SteerCar(float steerAngle) {
         wheelFL.steerAngle = steerAngle;
         wheelFR.steerAngle = steerAngle;
     }
 
     public override float[] Heuristic() {
 
         float motorTorque = 0f;
         float steerAngle = 0f;
 
         if (Input.GetKey(KeyCode.W)) {
             motorTorque = maxMotorTorque;
         }
 
         if (Input.GetKey(KeyCode.A)) {
             steerAngle = -0.5f;
         }
 
         if (Input.GetKey(KeyCode.D)) {
             steerAngle = 0.5f;
         }
 
         if (Input.GetKey(KeyCode.S)) {
             motorTorque = -maxMotorTorque;
         }
 
         return new float[] { motorTorque, steerAngle};
     }
 
     private void FixedUpdate() {
         if (GetStepCount() % 5 == 0) {
             RequestDecision();
         } else {
             RequestAction();
         }
     }
 
     private void OnCollisionEnter(Collision collision) {
         if (collision.transform.CompareTag("building")) {
             CarReverse();
         }
     }
 
     private void CarReverse() {
         wheelFL.motorTorque = -maxMotorTorque;
         wheelFR.motorTorque = -maxMotorTorque;
     }
 }

I can control the vehicle with keyboard buttons W, A, D but S is not reversing the car. Please help me on this. Let me know if I have to provide any more information. Also attaching an image of the scene. The red block is car, blue blocks are building, black strips are roads and rest is ground. alt text

screen-shot-2020-03-05-at-91148-am.png (258.1 kB)
screen-shot-2020-03-05-at-91148-am.png (258.1 kB)
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

258 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 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

Tron-like movement and retractable / reversible trail? 0 Answers

Tank controlling with wheel colliders?,Tank control on wheels? 0 Answers

How to get car to reverse using motorTorque/WheelColliders? 0 Answers

How to make a loose wheels?,How to create a loose wheels? 0 Answers

One of meshes keeps following the camera in scene mode for some reason? 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