- Home /
Apply force from the object axis
Hi everyone, I'd like to know if there is any possible way of adding forces to a sphere from its own axis, I mean, when I apply the force it applies to the "global axis" and i want it to the objects axis.Here is part of my script, where I add the force to the ball:
var ballVelocity=100;
var dir : Vector3 = Vector3.zero;
dir.x = Input.acceleration.x;
dir.z = Input.acceleration.y;
if (dir.sqrMagnitude > 1){
dir.Normalize();
dir *= Time.deltaTime;
rigidbody.AddForce(dir * ballVelocity);
}
if the ball is spinning in any way (for example, rolling around), its local axes are gonna be in a 'random' position every time you apply force, which would result in unpredictable behaviour.
an option that players might like would be applying forces from the camera's local axes, which are predictable and should make sense to the player. :)
look for 'unity camera relative movement' for the functions and stuff to convert directions from camera to world and back.
But if you do want local-axis forces, Fattie's got you covered.
Thanks for so quick responses :) That was the option i hoped will work well, but i didn't knew if it was possible. I see that it is... ;D Will this let me move a ball in the direction the cam is looking? Thanks again :)
Answer by Fattie · Apr 10, 2013 at 04:33 PM
do you mean AddForceAt ?
or do you mean this ??
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddRelativeForce.html
Thank you very much Fattie, I'm pretty sure the second one is the one that i could use, but now I'd read about unity camera relative movement, I'd like to try both hehe ;D Thanks for the quick response :)
HERE TO HELP !!
Could you please also read this very long answer and comments,
http://answers.unity3d.com/questions/418637/add-force-at-position-question.html
and you may like to, well, vote it up :) It's very helpful, I always liked that question but not many people read it. Note particularly the long comments at the end. CHEERS
Your answer
![](https://koobas.hobune.stream/wayback/20220613100046im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lerp a Object along X and Z axis only. 3 Answers
Tree position on random Terrain (y axis) 0 Answers
"Turn off" snapping of gameobjects inside editor? 5 Answers
Camera Following Spawned Object 2 Answers
Random ball generator? 1 Answer