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 Euge · Apr 19, 2016 at 02:50 AM · c#movementbugjumpjumping

While (starting jumping or in jump) holding W key makes game object jump high and fall slow.

This is my own upgrade to Roll-a-Ball game. So while starting jumping or already in jump pressing the W key(moving backwards relative to camera) makes game object jump higher and fall really slow (like with decreased gravity) than when jumping with A W or D keys pressed. (Also while pressing W key game object jumps not so high as when A or D are pressed, but it isn't a main problem) PlayerController script:

     public float speed;
     public Text countText;
     public Text winText;
     public float force;
 
     private AudioSource au;
 
     private int count;
     private Rigidbody rb;
 
     void Start()
     {
         rb = GetComponent<Rigidbody>();
         au = GetComponent<AudioSource>();
         count = 49;
         SetCountText();
         winText.text = "";
     }
 
     void FixedUpdate()
     {
         float moveHorizontal = Input.GetAxis("Horizontal");
         float moveVertical = Input.GetAxis("Vertical");
         Vector3 movement = new Vector3(moveHorizontal,0.0f, moveVertical);
         movement = Camera.main.transform.TransformDirection(movement);
         if (Input.GetKeyDown(KeyCode.Space))
         {
             if (rb.velocity.y < 0.001 && rb.velocity.y > -0.001 && count > 49)
             {
                 rb.AddForce(new Vector3(0.0f, force, 0.0f));
                 au.Play(0);
             }
         }
 
         rb.AddForce(movement * speed);
     }


This started after adding the movement = Camera.main.transform.TransformDirection(movement);

line, but I need it to move the Player relative to camera.

How can I improve it, how does this line even affect my game object this way?

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 Euge · Apr 19, 2016 at 03:27 PM

Ok, I understood the essence of the problem. Here's my cam script

     public GameObject player;
     public float speed;
 
     private Vector3 offset;
 
     void Start()
     {
         offset = transform.position - player.transform.position;
     }
 
     void LateUpdate()
     {             
         transform.position = player.transform.position + offset;
         transform.RotateAround(player.transform.position, Vector3.up, Input.GetAxis("Mouse X") * speed);
         transform.LookAt(player.transform);
         offset = transform.position - player.transform.position;
     }

The thing is that my camera always points at the Player from above at a certain angle. the "movement = Camera.main.transform.TransformDirection(movement);" pushes the ball to the ground when moving forward (when pressing W the force is applied to the ball pointing from camera to the ball center) and tries to lift player when pushing S key.

Now I'm thinking on a solution. Is there any way to make TransformDirection work in X-Z plane so i don't get these vertical forces?

Comment
Add comment · Show 1 · 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 Euge · Apr 19, 2016 at 03:45 PM 0
Share

Gosh, silly of me. Just need to put

     movement = new Vector3(movement.x, 0.0f, movement.z);

before

     rb.AddForce(movement * speed);

Works like a charm. Just needed that good night sleep. ##Topic closed.

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

Jump Using Raycast. 0 Answers

how can make my player to jump like parabola 1 Answer

My jump scripit wont work. i have been tryingtt o make it work for an eternity. please help. 1 Answer

how do I make my character jump while running without losing all your speed 1 Answer

Player looses ability to jump further right player moves. 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