Apply Force...on Local Axis?

Title just about covers it. Have I missed a node somewhere? Apply Force node works great for an object on global axis but there doesn’t seem to be an option or node for local axis? Is this something that’s planned to be added later or if not should I look at implementing a haxe solution?

Cheers,

The general way to apply something in the direction of a local axis is to use the Get Transform node, to get the transform of the object, then use the Vector From Transform node to get either its look, left, or up direction, then multiply that vector by the magnitude of the force/velocity/etc. that you want to apply:

Awesome, guess my node tree is going to get a bit busy but I suppose this gives far greater control. Still getting used to having more than 3 horizontal nodes in a chain coming from native BGE. Thanks for the explanation

Yeah, I really wish that there was just a “Use local co-ordinates” checkbox on the “Apply Impulse” node (or a dropdown to toggle between Global and Local), much like in BGE’s equivalent. It would definitely make life much simpler…

1 Like

That’s probably a good idea. You should open a GitHub issue.

1 Like

Done.

Incidentally, this is issue number 1234!! I choose to take this as a good sign. :stuck_out_tongue_winking_eye:

1 Like

This is definitely a good idea and I hope that it gets traction.

In general, I would like to see it become “even easier” to relate “things that are happening on a global, game-wide level” to “the coordinate space of a particular Thing.” (While working in the comfy, cozy context of Logic Nodes …)

a little question: considering the title of this post that is apply Force … and if we remember that a Force is responsible for the acceleration and not the speed of the object, is it the case with the results you obtain here ?

I haven’t tested it recently, but I’m pretty sure that is how it has worked for me in the past. I don’t see why it would be any different. The node calls Bullet physics to apply the force to a rigid body.

Forgive me if this should be posted under the Haxe category, but… I thought I’d have a go at doing this myself (without any knowledge of Haxe, or Armory, or well… much of anything programming related :stuck_out_tongue_closed_eyes: ) and I’m wondering if I’m going about this right…

So it seems that the vector the user inputs for the force is called impulse. It looks like a vector pointing towards the x / y / z local axis’ can be found from object.transform.world.look/right/up.

I’m guessing that basically the impulse x value needs to be multiplied by the local forward vector, the y by the right vector and the z by the up vector, and then all of those added together to get the final result.

So would the impulse vector, translated to local coordinates be defined by something like:

var forward = new Vec4();
var up = new Vec4();
var right = new Vec4();
var localImpulse = new Vec4();

forward = object.transform.world.look();
up = object.transform.world.up();
right = object.transform.world.right();

localImpulse = Vect4(impulse.x * forward.x,impulse.x * forward.y, impulse.x * forward.z).add(impulse.y * right.x,impulse.y * right.y, impulse.y * right.z).add(impulse.z * up.x,impulse.z * up.y, impulse.z * up.z)
  
impulse = localImpulse;

var rb:RigidBody = object.getTrait(RigidBody);
rb.applyImpulse(impulse);

???

PS Apologies to any devs if the code above makes your eyes bleed! :sob:

@Armored_Blob I see now that mean now an impulsion.

Speaking of impulse, normally you speak about the pulse, that is a vector quantity acting in the same direction as the Force that creates the pulse.

Thus now the pulse will act on an object has the effect of changing the amount of movement.

@Armored_Blob It looks like @Simonrazer beat you to it:

About your code, though, I’ll go through as quick as I can:

Force Is Not the Same as Impulse

Force is a, well, force applied to an object that will result in the object increasing in speed in the direction that the force is pushing. Gravity is an example of a force applied to an object, it will make the object go faster and faster down towards the earth. A force applied in Armory will do the same thing.

An impulse on the other hand is the result of a force applied for a period of time, even if that time is extremely small. A baseball bat hitting a baseball is an example of an impulse. The baseball bat applies an impulse to the baseball. Unlike a force, an impulse won’t make the ball go faster and faster. It will accelerate the ball to a certain speed in an instant and then stop. Like a player jump.

Getting the Local Direction

The way that you are thinking of getting the direction of the impulse is not correct, though the code you wrote to achieve what you were thinking seems to be well formed. :slight_smile:

So force ( and impulse ) is a vector. Vectors are a value made up of a direction and a magnitude that can be represented in 3D space with three scalar ( or 1 dimensional ) values ( And we use Vec4’s to represent 3 dimensional values in Armory. See comment. )

In this particular instance, you want to apply a force with specific magnitude that represents how hard you want to push the object. For this instance lets just say that the magnitude is 5. Then you want to apply this force in the direction that the object is looking.

The object.transform.world.look() gives you a vector with a magnitude of 1 and a direction in the object’s look direction. This is nearly what we want, all we have to do is get the magnitude right. We do this by multiplying the vector by our desired magnitude, 5.

var magnitude = 5;
var impulse = object.transform.world.look().mult(magnitude);
var rb:RigidBody = object.getTrait(RigidBody);
rb.applyImpulse(impulse);

Hope that helps!