BL Coding Trying to make the main Agent fly

Users who are viewing this thread

Digitus Munchus

Team: Romans
Hi there, I'm looking for some guidance regarding ways to make an Agent fly (the main Agent here).
TLDR below.

Here is what I've tried, all through ScriptComponentBehavior uses:
=> Binding the ScriptComponentBehavior to an empty GameEntity, then giving the entity some physics properties, with the following lines:
GameEntity.AddSphereAsBody(Vec3.Zero, 1, BodyFlags.Dynamic);
GameEntity.AddPhysics(75, GameEntity.CenterOfMass, GameEntity.GetBodyShape(), Vec3.Zero, Vec3.Zero, PhysicsMaterial.GetFromName("missile"), false, 1);
GameEntity.SetPhysicsState(true, false);
And then using OnTick:
Vec3 impulse = new Vec3(0, 0, 50);
GameEntity.ApplyLocalImpulseToDynamicBody(GameEntity.CenterOfMass, impulse);
This one worked like a charm, was one of my most successful experiments so far, but sends an empty sphere flying, not the Agent... So I then tried adding the Agent as a child entity to the sphere, which didn't work (The Agent stayed on the ground and animation speed got doubled as a side-effect).

I then found the decompiled code which sticks arrows to shields on collision, and had the idea to use that to create some kind of jetpacks, by sticking the flying sphere to the Agent... I tried playing around with the TransformToParent/TransformToLocal functions, which seemed to be how that fusion between MatrixFrames is done, but nothing I tried worked, and I think I don't understand these functions well enough.

=> I tried to use ApplyLocalImpulseToDynamicBody when binding a ScriptComponentBehavior to the MainAgent, which would have been absolutely ideal (and could be reused for explosions !), but the game crashes at that specific function, saying I'm trying to access something protected. It wasn't an exception, and debugging with dnSpy couldn't catch anything, so my guess is this comes from the Engine directly ?
I tried to change the Agent's body flags/physics to make them similar to the flying sphere, in case the Agent didn't have a dynamic body, but nothing worked.

=> I tried calling agent.TeleportToPosition every tick while increasing its origin.z, didn't work, it just made my Agent surf on rocks in town, and teleport on roofs when a roof was closer to my z position. So it seems TeleportToPosition forces the Agent to stay on the ground, and it's an engine function.

=> With the ScriptComponentBehavior still bound to the MainAgent, I tried every tick to just GetGlobalFrame onAgentVisuals, change the frame's origin.z, SetGlobalFrame with the updated frame, but the Agent didn't refresh correctly and was still considered on the ground, only its sword was flying.
I then tried to do _agent.AgentVisuals.SetEntity(_agent.AgentVisuals.GetEntity) to force a refresh, which made the Agent appear in the air too, but the Agent was considered on the ground too for collision purposes, and it couldn't go above walls with being 30m higher than them... So the refresh was incomplete.

TLDR / So here are my questions:
1. I'm using agent.AgentVisuals.GetEntity() to get the Agent's Entity, am I doing this right or is there something else I should know ?
2. How can I make ApplyLocalImpulseToDynamicBody work on the main Agent without crashing ? I believe enabling modders to do so would help us immensely regarding the creation of flying units or when coding explosion effects.
3. If I set the Agent's position manually, what's the proper way to refresh it without losing my changes at the beginning of every tick ?
4. Can you please explain to me how the MatrixFrame.TransformToParent/TransformToLocal work ?
5. Would binding some kind of jetpack on an Agent bone work, or would the Engine force it to stay on the ground ?

Last edited:
Top Bottom