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 _philip · Jan 18, 2015 at 12:47 AM · constantforce

Applying a constant force to a ball along the camera axis.

Hi, I have this ball I'm trying to apply a constant force to when the W key is pressed. I have a camera which follows the ball and always looks at it. The camera can be moved around the ball by using the mouse (similar to how you can move the camera around a world of warcraft character). I'd like to apply the force to the ball in the direction the camera is looking ( again similar to how you would move a character forward in world of warcraft). This is the code I've wrote to do it.

 var forwardValue = 15;
 
 function Update () 
 {
 
     //Forward
     if (Input.GetKey ('w'))
     {
         var cam : Transform = Camera.current.transform;
         var cameraRelativeForward : Vector3 = cam.TransformDirection (Vector3.forward);
 constantForce.force =  Vector3(constantForce.force.x, constantForce.force.y, 
 cameraRelativeForward.z * forwardValue);
 
     }
     
     //Stationary
     else if(Input.GetKeyUp ('w'))
     {
         constantForce.force =(cameraRelativeForward * 0);
         
     }
 }

The problem is the force only moves the ball along the global z axis and it only applies the maximum force when the camera's z axis is aligned with the global z axis. If the z axis of the camera is aligned with the global x axis the ball doesn't move at all.

If I change this

 constantForce.force =  Vector3(constantForce.force.x, constantForce.force.y, 
 cameraRelativeForward.z * forwardValue);


to this

 constantForce.force = (cameraRelativeForward * forwardValue);

it has the desired effect but it presents another problem in that later I would like to apply a constant force along the camera's x axis to the ball, but this above code sets the constant for for all 3 axis and so the two forces would be conflicting with each other.

Thank you.

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

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

2 People are following this question.

avatar image avatar image

Related Questions

Add wind effect to Game Object 1 Answer

what is the comand for global torque using constant force 1 Answer

rotating constantly 1 Answer

Constant Running on x axis 0 Answers

keep my collider on my particle system close together 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