Local object physics - noob scripting Q: velocity

I’m new to Haxe and amateur at script in any language.

Problem: trying to utilize physics set/get velocity features from within a script but not sure what file(s) / package to import (KodeStudio keeps spitting out errors about not finding the function definition). Or is it called something else outside of the logic node? I’m trying to access and change values that are also found in setAngularVelocity() from the the velocity logic node(s).

The node system is awesome and does all of the basic stuff I need (and I really appreciate those of you working on armory3d), but I’m trying to get angular physics to have a local effect on an object by using a custom Haxe script to manipulate a few nuances of how physics elements are applied.

Any help or links are appreciated!

PS
Apologies if this is covered somewhere already; if so, I would be grateful for a link.

I did see this link and maybe my question is in the wrong forum space.

I have tried accessing rigidbody properties with Haxe and though I can do some things with it, I still can’t figure out how to manipulate velocity data from a Haxe script.

I am sure this is an issue with my low-level of understanding on the matter, so if someone smart wants to have pity on me… :slight_smile:

Don’t worry, everyone has to start somewhere. I recommend checking the armory examples and the templates from the official repo to see some examples of things already done working, more specifically the platformer/first-person/third-person templates, check the scripts source for those projects to have some examples of code.

1 Like

thanks for the reply!

I have checked out some of the exmaples (they’re great). For the fps and camera control (and others), I can get those working and fumble my way through my syntax and grammar errors to do my own things with the functions and examples. Was there a specific example on git that you were thinking about?

Where I get confused is on “import / package” - I’ve worked mostly with php and am familiar with the concept of importing a file or resource that is defined somewhere else so that you have scripting access to the functionality. What I am not sure of is which file / feature to import to gain scripting access to velocity of an object (and if it’s even called velocity or if that’s just what the velocity node uses as a name). Or should I be researching Vec4? If you don’t know if you’re using the right feature it’s difficult to differentiate syntax error from improper / invalid process when learning.

Additionally, I have a hard time learning details -> out (but am willing). However, if there’s a big picture down to details way of looking at it; one where a lot of information can be inferred from broader principles, explaining it may help more than just me.

I’ll head back to those examples and see what else I can learn that may help.

Thanks and best to you!

I’m guessing everything that I need is in this:

Is this generally how others learn this type of thing as a noob (look at other’s stuff and try to understand it)? If so, we can mark this as “solved.”

For some reason I thought this would be more about how to understand the api features and know where to “import / package” stuff from. In any case, I’m sure that I am drenched in speech revealing my amateur comprehension of things. :slight_smile:

I’ll stop posting so much. Thanks for the help and grateful to lubos & armory community for a pretty dang nifty tool!

Answering your first question, package is basically the directory to which the file can be accessed from, like “iron.object.CameraObject”, the path would be “iron.object” to access CameraObject in another file, Normally is recommended to leave it at “package arm” to avoid package conflicts, but you can change it if you will. Import it’s as the names indicates to import or include the content of a file into another, much like include or require from PHP, i.e. if you want to use the Vec4 class, you have to import it like “import iron.math.Vec4;”.

In the third person template you can see that here ThirdPersonController.hx#L208 the velocity of “body” is modified directly but before that is activated just in case body was sleeping:

body.activate();
body.setLinearVelocity(dir.x, dir.y, btvec.z - 1.0);

What is body? If you search you will not see a declaration of body anywhere, but we can see that in this case the class ThirdPersonController extends the content of CameraController, that is that ThirdPersonController inherits from CameraController, so if you go to “path-to-SDK/armory/Sources/armory/trait/internal/” you’d find CameraController.hx which seems to have some prepared declarations so you don’t have to do them yourself, and there it’s body:

16: var body:RigidBody;

body is declared as a RigidBody and then it’s assigned to it the rigidBody trait of the object

30: body = object.getTrait(RigidBody);

The rigidBody trait being: enabling RigidBody inside Blender in the object in the physics tab.

One thing I found useful to learn from the engine is to see something working and then reading the source to understand what it does, being that one of the advantages of Armory is that a lot of the source is in the same language, so you don’t have to learn a lot of different languages to get some grasp of what is going on behind the scenes, the search tool inside Visual Studio Code helps a lot too, if you set the project folder to the SDK, you can search for a function and it will show where is used and where is located the source.

1 Like

Solved and that makes so much sense! Thank you a ton for taking the time. The full explanation is gold.

I don’t know why I didn’t look at 3rdPersonCamera bundle first (forum listening: fail).

You made my day - thanks, again!