Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Foolsbry · Nov 25, 2014 at 11:36 AM · physicsgravitycarendless runner

Endless Runner Car Physics Issues (Again)

Hey there, I recently posted about some trouble I was having controlling a car in an endless runner. I have a script, which most is from an online tutorial for a different style of endless runner, but it's just not working for me.

 public class SimplePlayerControl : MonoBehaviour 
 {
     public float PlayerSpeed;
     public float turnAngle;
     private float PlayerInput;
     private float PlayerMove;
 
 
     void Update()
     
     {
             PlayerInput = Input.GetAxis ("Horizontal");
             PlayerMove = PlayerInput * PlayerSpeed;
     }
 
     void FixedUpdate () 
     
     {
         rigidbody.velocity = new Vector3(PlayerMove, -1f, 0.0f);
         rigidbody.rotation = Quaternion.Euler (rigidbody.velocity.y, rigidbody.velocity.x * turnAngle, rigidbody.velocity.z);
 
     }
 }
 

That's the playerController script. My issue is that the car doesn't react to gravity properly because of this line:

rigidbody.velocity = new Vector3(PlayerMove, -1f, 0.0f);

But I just don't know what else I can use. All I want to do is move the car from left to right as needed on the X axis, and lock it on the Z axis. Right now, when in mid air, the car moves left to right fine, however when it hits the ground it jiggles in spot and doesn't want to move left or right very easily. It has a fairly flat, long rectangular box collider for collision so any contact with the ground should be smooth. I've also set collision detection to continuous and interpolate is on.

The other issue I'm having is I'm attempting to lock the car on the Z axis so it doesn't go too far forward or too far back. It works for the most part, however after several jumps the car begins to lag behind and eventually falls off screen. To achieve this I just locked the z-axis position on the rigidbody of the player car. Is there a better way I can do this that will actually work?

Thanks for your help!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Foolsbry · Nov 26, 2014 at 05:40 AM

I've discovered physics materials and have solved my issue by changing the script a little bit and giving the player a collider that has no friction. Now my only issue is with rotation.

When I take out this line:

rigidbody.rotation = Quaternion.Euler (rigidbody.velocity.y, rigidbody.velocity.x * turnAngle, rigidbody.velocity.z);

The car moves left and right in the world fine (although it doesn't stay locked on the z axis for some reason), the car rotates pretty freely when colliding with objects and can sometimes end up facing the wrong way.

Does anyone know of a way to lerp to the correct rotation? I'm assuming I would want it to check if its rotation on the correct axis is 0 degress (facing forward) and if it's not, then lerp from its current position to the desired position.

Thanks again for anyone's help.

Comment
Add comment · Share
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

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

2 People are following this question.

avatar image avatar image

Related Questions

Rigidbody, Front slides toward Gravity down Hill 0 Answers

Rollcage-like car gravity 0 Answers

Physics driven cars without Wheel Colliders. Is it practicable? 1 Answer

Strange behaviour when WheelColliders are on their side. 0 Answers

Constant force, with gravity, and correct collisions. 2 Answers


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