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 Doodayer · Sep 24, 2014 at 01:27 AM · bugjumpglitch

Jumping causes strange bugs and messages

Every time i jump the player disappears off the screen and in the inspector the Transform Position Y changes at alarming rates. I also get this message in the Inspector Transform tab - "Due to floating-point precision limitations, it is recommended to bring the world coordinates of the GameObject within a smaller range." What does this mean?

Heres the source code if it helps: using UnityEngine; using System.Collections;

 public class Move : MonoBehaviour
 {
     public float moveSpeed = 7f;
     public float turnSpeed = 150f;
     public float jumpSpeed = 0.25f;
     
     void Update ()
     {
         if(Input.GetKey(KeyCode.W))
             transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
         
         if(Input.GetKey(KeyCode.S))
             transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
         
         if(Input.GetKey(KeyCode.A))
             transform.Rotate(Vector3.up, -turnSpeed * Time.deltaTime);
         
         if(Input.GetKey(KeyCode.D))
             transform.Rotate(Vector3.up, turnSpeed * Time.deltaTime);
 
         //jump test
         if (Input.GetKey (KeyCode.Space) && !Gravity.boolGravity) {
             rigidbody.AddForce(Vector3.up * jumpSpeed);;
             Gravity.boolGravity = true;
         }
     }
 }
Comment
Add comment · Show 1
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
avatar image Habitablaba · Sep 24, 2014 at 01:51 AM 0
Share

What is the mass of the attached rigidbody?
Also, have you tried using 'AddForce' for all of the movement, ins$$anonymous$$d of just jump?
Also also, have you tried moving the 'AddForce' bit to FixedUpdated?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Atonez · Sep 24, 2014 at 01:52 AM

In your code I see that you have (-Vector3.forward moveSpeed Time.deltaTime), And you have Vector3.up, -turnSpeed * Time.deltaTime)try instead:

Vector3.forward (-moveSpeed Time.deltaTime); Vector3.up, (-turnSpeed * Time.deltaTime);

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
avatar image
0

Answer by Doodayer · Sep 24, 2014 at 02:32 AM

ok so i fixed it by changing my rigidBody mass, but now i need to know how to do one of two things.

I could either use a timer to set boolGravity back to true, or i could make it to where when my players y value reaches a certain value such as 6 or 10 it sets it back to true.

If i do option one, i'll need a lot of help as i have no experience with timers in C# If i do option two, all i need to know is how to use an if statement to access my players y value.

thanks for all the help!

Comment
Add comment · Show 5 · 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
avatar image Habitablaba · Sep 24, 2014 at 02:54 AM 0
Share

Why not have gravity always on? You could also put a small collider as a trigger at the feet of your player and manage the gravity bool in OnTriggerEnter and OnTriggerExit

avatar image Doodayer · Sep 24, 2014 at 03:53 AM 0
Share

With gravity always on, the player begins to dig into the ground object, and eventually either going through, or beginning to levitate and fly in circles.

avatar image fotaras · Sep 24, 2014 at 04:11 AM 0
Share

As i told you, use rigibody.move to prevent that. Tralslate does not tace into account collition thats why it digs into de ground.

avatar image Habitablaba · Sep 24, 2014 at 04:24 AM 0
Share

I agree, that's probably your best bet.

avatar image Doodayer · Sep 25, 2014 at 04:07 AM 0
Share

so why when i use this code: rigidbody.AddForce(Vector3.down * playerGravity); it makes my player start moving into the ground when i move? that's my main problem is that the collision never stops and he starts going into the ground and then flying when it pops back out.

avatar image
0

Answer by LSPressWorks · Sep 25, 2014 at 04:18 AM

They have answered your question like 5 times already. There is seldom a need to add gravity manually. Is there a reason for it?

as for the other

 var OldPosition : Vector3;
 
 if(jumping != false)
 {
 if(Vector3.Distance(oldPosition,newPosition) > value)
 {
 jumping = false;
 }
 
 }

there are about 70,000 methods for that though. Once jumping is false, you can use whatever code you wish once the condition is met.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Weird double-tap bug when I use standart controller (Android) 0 Answers

Why is unity lagging so much? 1 Answer

Editor Camera moving while rotating 0 Answers

Changing Skybox tint in game, permanently changes it in editor? 1 Answer

Sprites Leaving Trails Glitch? 0 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