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 IceBlackSanctum · Feb 08, 2015 at 07:37 PM · camerarotationrigidbodyforcemoving

Problem when applying forces to a ball

Hi,

I've got a problem with my game, I want to make forces on a ball to rotate it and to move it forward. I've asked before for a problem with my camera and mouse (http://answers.unity3d.com/questions/892634/how-to-apply-a-force-forward-depending-of-the-came.html), and now, I've got a new problem. And the people who responded me don't tell me more (they're maybe dead ? :D, no, they answer other ^^)

Well so the problem is that I want to make forces in terms of the view of the camera, it work... a few... I don't want to apply force in the Y axe (the ball don't fly), but forces is applyed in the Y axe and I don't understand why..

When we go forward, there is -5 applyed on the Y-axe which slowdown hardly the ball and when we go back... OMG 5 in Y.. We begin to soar (it is the best word I think but fly is more understandable).

Well this is the code (in Javascript), you can give me C# script, I will understand :

 // Initialisation
 var speed = 8.0;
 var force : Vector3;
 var vec : Vector3;
 
 function Update () {
      if (Input) { // If we push any button
          vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime; // X-axe
          vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime; // Z-axe
          vec = Camera.main.transform.TransformDirection(vec.x, 0, vec.z); 
          // As you see, 0 to Y-axe, and it is in terms of the camera's view
          force = vec.normalized * speed; 
         // Normalize the vector and multiply with the speed
          rigidbody.AddForce(force); // Apply the Vector3 to the rigidbody
      }
 }

Well, I don't understand the prob.. A short screen : http://puu.sh/fvOlZ/4bb42782a9.jpg as you see, there is force applyed on the Y axe.

Thank you a lot,

IceBlack,

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 AngryBurritoCoder · Feb 08, 2015 at 09:13 PM 0
Share

not sure but... ins$$anonymous$$d of

 vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime; // X-axe
           vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime; // Z-axe
           vec = Camera.main.transform.TransformDirection(vec.x, 0, vec.z); 

try...

 vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime; // X-axe
 vec = Camera.main.transform.TransformDirection(vec.x, 0, 0); 
 vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime; // Z-axe




avatar image IceBlackSanctum · Feb 10, 2015 at 07:24 PM 0
Share

Hi, firstly sorry for the time a make to answer.

I'm sorry but it doesn't work. I can't translate now on the Z axis and I need ^^

I try a thing. I make a EmptyObject at the position of my ball and I put it on my camera. Also I change my code.

 var origine : GameObject;
 [.....]
 vec = origine.transform.TransformDirection(vec.x, 0, vec.z);

And now the force on Y is less. I think I understand thanks to this the prob. The Empty Object is bit high from my ball so the ball want to go into. I think.

EDIT : no sorry it doesn't work, so I don't understand the prob

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by IceBlackSanctum · Feb 10, 2015 at 08:31 PM

Oh god... I found the problem....

I put "vec.y = 0;" after "vec = origine.transform.TransformDirection(vec.x, 0, vec.z);" and it work great. I don't understand why.. But it work as that. So the code is :

 var speed = 8.0;
 var force : Vector3;
 var vec : Vector3;
 
 function Update () {
     if (Input) {
         vec.x = Input.GetAxis("Horizontal") * 25 * Time.deltaTime;
          vec.z = Input.GetAxis("Vertical") * 25 * Time.deltaTime;
         vec = Camera.main.transform.TransformDirection(vec.x, 0, vec.z);
         vec.y = 0;
         force = vec.normalized * speed;
         rigidbody.AddForce(force);
     }
 }


Thanks a lot !!

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 do I rotate the propellers on this drone? 1 Answer

Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers

How to always face player relative to player's rotation and how do I use TransformDirection to move a player regardless of Y-rotation? 0 Answers

How to apply a force forward depending of the camera 2 Answers

Add force on camera using AddForce 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