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 Alamarche · Dec 20, 2015 at 03:22 PM · transform3dgravityfirst-persontransform.forward

How do you maintain gravity using transform.forward and transform.right?

I'm making my own first-person game and I have this problem where whenever I move after jumping, the player slowly falls to the ground. I know that when I use transform.forward the y values of the player are being set to 0 and the downward force is basically being reset, that's why it falls slowly. I just need help finding a way to maintain the gravity of the player.

I know I can use a character controller and all that, but I want to learn how to do it this way. I'm willing to change the code around, I just don't want to use a controller. Thanks :)

Here's the code:

     void Update () {
         if(Input.GetKey(KeyCode.A)){
             transform.position += -transform.right * Speed * Time.deltaTime;
         }else if (Input.GetKey(KeyCode.D)){
             transform.position += transform.right * Speed * Time.deltaTime;
         }
         if(Input.GetKey(KeyCode.W)){
             transform.position += transform.forward * Speed * Time.deltaTime;
         }else if (Input.GetKey(KeyCode.S)){
             transform.position += -transform.forward * Speed * Time.deltaTime;
         }
     }

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 Alamarche · Dec 20, 2015 at 09:34 PM 0
Share

I changed the transform.position += to ridgidbody.velocity = so that the player could easily collide with objects. Jumping is even worse though. The jump is extremely small and the fall is super slow. Still up for any ideas though.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Player and gun rotation problems in FPS shooter 0 Answers

Bug floating object when fixed to bones 0 Answers

Unity Lerp does not work correctly when gameObject rotation changes 0 Answers

Ello~ I need help with transform.parent = null; When I play it and press the DropWeapon input button it goes in a random location and doesnt move . 0 Answers

Rotate transform to match another, but not past 180° 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