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
1
Question by Asma_Naser · Dec 17, 2014 at 10:06 PM · rigidbodycharacterdownfall

My character fall down on the ground ?

Please I want your help! My character keeps falling down not through the ground, i did the rigidbody and i did the tick on the use gravity but it still falls... please help me!

public float Sp; public float gravity = 20.0F; private Vector3 moveDirection = Vector3.zero;

 // Use this for initialization
 void Start () {

 }
 
 // Update is called once per frame
 void Update () {


     // this code will make the character jump
     if (Input.GetKeyDown ("space")) {
     transform.Translate (Vector3.up * 400 * Time.deltaTime, Space.World);
             }

     moveDirection.y -= gravity * Time.deltaTime;

     if (Input.GetKey (KeyCode.RightArrow)) {
         
         transform.position += Vector3.right * Time.deltaTime * Sp;
         
     }
     
     // this code is to make the object move to the left in every second by pressing the left arrow
     if (Input.GetKey (KeyCode.LeftArrow)) {
         
         transform.position += Vector3.left * Time.deltaTime * Sp;
         
     }
     
     // this code make the object position move forward in every second by pressing on the up arrow
     if (Input.GetKey (KeyCode.UpArrow)) {
         
         transform.position += Vector3.forward * Time.deltaTime * Sp;
         
     }
     
     // this code make the object move back if the user press the down arrow in the keybord
     if (Input.GetKey (KeyCode.DownArrow)) {
         
         transform.position += Vector3.back * Time.deltaTime * Sp;
         
     }

}

alt text

ded.png (263.2 kB)
Comment
Add comment · Show 2
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 Asma_Naser · Dec 17, 2014 at 05:44 PM 0
Share

thaaaanks a lot, if i want to use force how can i use it. i used rigidbody to make my character collect money :)

avatar image MrSoad · Dec 17, 2014 at 05:48 PM 0
Share

Take a look at this page of the docs, you might want to create a test scene in your project to have a play around with physics and forces as there is a lot to learn :)

http://docs.unity3d.com/ScriptReference/Rigidbody.AddForce.html

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by MrSoad · Dec 17, 2014 at 04:40 PM

The problem is that you are using the rigidbody and gravity is doing what it would in real life, the result being what you see in your pic above.

Do you really need to use a rigidbody and physics for this? You are moving your character by transform.Translate and transform.position which is not good if you do want to use physics, you should use forces instead.

If you do want to stick with physics then in your rigidbody settings look at "Constraints", now under "Freeze Rotation" click "X" and "Z". This will allow the character to rotate around the Y axis (rotate left and right) but not along the others(which would allow it to fall down).

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to use character controller to push down hinge joint properly 1 Answer

Velocity for movement 0 Answers

Rigidbody character controller issues 0 Answers

Configurable Joint - What does Position Spring and Damper mean? 1 Answer

Tweaking character movement 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