Dear Everyone,
I am happy to report that I've learned how to dynamically change the physical mass property of a KActor while in game.
I am serious folks, I've actually had my KActor Jump, and while in mid-air, pressed a button, changed its mass higher, watched it fall, then found it much harder to move using my WASD setup.
Then, I pressed another key, and the KActor was back to its normal self again!
I've repeated this several times in same gaming session, it works fabulously!
~~~
Dynamically Change Mass of KActor In Game
Here's the function you can add to your custom KActor class
Things to note:
1. RB_BodySetup is not a struct, its a class, you have to create an instance using new
2. There are many properties of RB_BodySetup, MANY. and we are only changing a single one, MassScale
3. Kactors have this thing called StaticMeshComponent, which is different than pawns and other actors, and applies only to things like DynamicSMActors and KActors that run with physics engine so directly.
We are first retrieving the RootBodyInstance of the KActor's StaticMeshComponent,
and then calling update function on this retrieved info.
I piled the code together to avoid un-needed local variables;
4. Default MassScale is 1, its relative to the original properties and phys-Material of the KActor and its Mesh that you are working with.
5. A massScale of 10 is 10 times heavier as far as I can tell (thus the phrasing Scale in MassScale), so you will certainly notice a big shift if you try 10 as a first sample
6. more realistic change would be more like 1.7 or 2, for 2 times as heavy.
7. If you want to modify a KActor from elsewhere in your game engine, just change Self to the name of your KActor class instance variable (myHappyKActor.StaticMeshComponent.....)
8. It Works!!! Yay! Change the Mass of a KActor any time you want!
I had to sort through a lot of unreal documentation to figure out a working way to do this.
I hope my research helps you all out!
I posted this as a thread by itself in case you want to share your own way of doing what I am writing about here, if you think you have a more effective way.
Joy to you!
Rama
I am happy to report that I've learned how to dynamically change the physical mass property of a KActor while in game.
I am serious folks, I've actually had my KActor Jump, and while in mid-air, pressed a button, changed its mass higher, watched it fall, then found it much harder to move using my WASD setup.
Then, I pressed another key, and the KActor was back to its normal self again!
I've repeated this several times in same gaming session, it works fabulously!
~~~
Dynamically Change Mass of KActor In Game
Here's the function you can add to your custom KActor class
Code:
function setMass(float newMass) { local RB_BodySetup rbs; //invalid values if(newMass <= 0) return; rbs = new Class'RB_BodySetup'; rbs.MassScale = newMass; ( Self.StaticMeshComponent.GetRootBodyInstance() ).UpdateMassProperties(rbs); }
1. RB_BodySetup is not a struct, its a class, you have to create an instance using new
2. There are many properties of RB_BodySetup, MANY. and we are only changing a single one, MassScale
3. Kactors have this thing called StaticMeshComponent, which is different than pawns and other actors, and applies only to things like DynamicSMActors and KActors that run with physics engine so directly.
We are first retrieving the RootBodyInstance of the KActor's StaticMeshComponent,
and then calling update function on this retrieved info.
I piled the code together to avoid un-needed local variables;
4. Default MassScale is 1, its relative to the original properties and phys-Material of the KActor and its Mesh that you are working with.
5. A massScale of 10 is 10 times heavier as far as I can tell (thus the phrasing Scale in MassScale), so you will certainly notice a big shift if you try 10 as a first sample
6. more realistic change would be more like 1.7 or 2, for 2 times as heavy.
7. If you want to modify a KActor from elsewhere in your game engine, just change Self to the name of your KActor class instance variable (myHappyKActor.StaticMeshComponent.....)
8. It Works!!! Yay! Change the Mass of a KActor any time you want!
I had to sort through a lot of unreal documentation to figure out a working way to do this.
I hope my research helps you all out!
I posted this as a thread by itself in case you want to share your own way of doing what I am writing about here, if you think you have a more effective way.
Joy to you!
Rama
Comment