- Home /
AddForceAtPosition Locally Problem.
Hello.
I am trying to control a Rigidbody 0 gravity space ship with local thrusters for a full physics movement, I have read the docs and i seem to be doing everything right or so i think.
For my tests i have a cube for main body and 2 other cubes at the back "1 back left, 1 back right" what i am trying to achieve is when i press A (left engine) the ship turns right with force from that engine locally, D (right engine) turns the ship left with force from the right engine locally, but for some reason both of my engines no matter where i put them force the ship to start spinning clockwise, Any ideas where i went wrong? Thanks.
#pragma strict
var leftEngine : GameObject;
var rightEngine : GameObject;
var currentPosition1 : Vector3;
var currentPosition2 : Vector3;
public var speed : float;
function Start ()
{
leftEngine = GameObject.Find("LeftEngine");
rightEngine = GameObject.Find("RightEngine");
}
function Update ()
{
if(Input.GetKey(KeyCode.A))
{
currentPosition1 = leftEngine.transform.localPosition;
rigidbody.AddForceAtPosition(Vector3.forward * speed, currentPosition1);
}
if(Input.GetKey(KeyCode.D))
{
currentPosition2 = rightEngine.transform.localPosition;
rigidbody.AddForceAtPosition(Vector3.forward * speed, currentPosition2)
}
}
Ship Structure:
-Hull
-leftEngine
-rightEngine
Design:
[ ] -hull
[] [] -engines
Been over it countless times, It is probably something so simple, But i am still learning. I am not looking for anyone to write me a new script, just a hint will go along way please. Thanks.
Have you tried using Force$$anonymous$$ode.Impulse ? Use it as the third parameter in AddForceAtPosition
Yes unfortunately that did not work, It is strange, the physics just want to keep rotating the ship clockwise no matter what i change or how i have the ship assembled.
Answer by SirAstral · Jan 27, 2015 at 01:14 AM
sometimes odd things will happen with unity and physics. I have been playing with a few lately myself.
Verify all of the basics. Make sure that all of your geometries are squared... as in, make scale 1x1x1 and rotation of 0,0,0 for all of your objects on the ship. Verify that the drags on all rigid-bodies are matching perfectly. Are you using any Wind or other physics things that might push or pull on your ship?
If your engine cubes are children of the parent cube, you should make sure they are in positioned on each other perfectly before you add them together and move them, or move them to position first then add them to parent. I have had funny business happen myself, especially with transforms in relation to their parents if I move one around from parent to child making changes along the way.
Thank you for the reply, I actually gave up on that approach and went with a modular approach. Each thruster now has its own "thrust" script then i am accessing them from within my ship controller, For now while testing the thrusters are only connected to the ship using "fixed joint"
The nice thing about using fixed joints is i can have engines / thrusters blown off ships which in turn will effect how they can manoeuvre.
The bad thing is they wobble all over the place like jelly :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613181615im_/https://answers.unity.com/themes/thub/images/avi.jpg)