ObjectReference - GetMass Unreliable

Post » Wed Jun 20, 2012 10:41 pm

So, I decided I would make an AoE push spell, easy enough, just use PushActorAway? Except it usually just pushes them over and their body slides on the ground, it doesn't send them flying, not cool enough. ApplyHavokImpulse sounds like it would be good, trick to applying a havok impulse on an actor is to push it first to set it as a ragdoll.

So yeah okay, seems to work fine just setting a fixed amount of impulse force, but when I want to factor the mass of the actor to multiply the force so it pushes heavy actors harder apparently it often times returns zero for the mass, doesn't particular have any good reason for doing so, at first I thought it was because I was spawning creatures and their 3D wasn't entirely loaded but that didn't seem to be the case. Is there some hidden havok registration for an actors mass?
Spoiler
Scriptname ImpulseEffect extends ActiveMagicEffectfloat Property VerticalStrength Autofloat Property MassMultiplier Autofloat Property MaximumRadius Autobool Property ThrowTeammates AutoEvent OnEffectStart(Actor akTarget, Actor akCaster)float distanceTo = akCaster.GetDistance(akTarget)If ((ThrowTeammates == false && akTarget.isPlayerTeammate() == false) || ThrowTeammates) && distanceTo < MaximumRadius  float targetMass = akTarget.GetMass()  If targetMass == 0   If akTarget.Is3DLoaded()	Debug.Trace(akTarget + " 3D loaded, re-acquiring mass: " + akTarget.GetMass())   EndIf   targetMass = 100  EndIf  float x_mod = -(akCaster.GetPositionX()-akTarget.GetPositionX())  float y_mod = -(akCaster.GetPositionY()-akTarget.GetPositionY())  float z_mod = -(akCaster.GetPositionZ()-akTarget.GetPositionZ())  float force = (targetMass * MassMultiplier) * (1.0 - distanceTo / 1000.0)  akCaster.PushActorAway(akTarget, 0)  akTarget.ApplyHavokImpulse(x_mod, y_mod, z_mod + VerticalStrength, force)  Debug.Trace("Throwing actor: " + akTarget + \	   " mass: " + targetMass + \	   " dist: " + distanceTo + \	   " massmult: " + MassMultiplier + \	   " result: " + (targetMass * MassMultiplier) + \	   " force: " + force)EndIfEndEvent

[03/29/2012 - 10:39:14PM] [Actor < (FF000F64)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:14PM] [Actor < (FF000F69)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:14PM] [Actor < (FF000F6C)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:14PM] [Actor < (FF000F6E)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:14PM] [Actor < (FF000F6D)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F6D)>] mass: 100.000000 dist: 58.905708 massmult: 15.000000 result: 1500.000000 force: 1411.641479[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F69)>] mass: 100.000000 dist: 165.184998 massmult: 15.000000 result: 1500.000000 force: 1252.222534[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F65)>] mass: 100.000000 dist: 194.941116 massmult: 15.000000 result: 1500.000000 force: 1207.588379[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F5B)>] mass: 100.000000 dist: 110.589050 massmult: 15.000000 result: 1500.000000 force: 1334.116455[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F64)>] mass: 100.000000 dist: 116.025391 massmult: 15.000000 result: 1500.000000 force: 1325.961914[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F6C)>] mass: 100.000000 dist: 120.227722 massmult: 15.000000 result: 1500.000000 force: 1319.658447[03/29/2012 - 10:39:15PM] Throwing actor: [Actor < (FF000F6E)>] mass: 100.000000 dist: 115.532143 massmult: 15.000000 result: 1500.000000 force: 1326.701782[03/29/2012 - 10:39:20PM] [Actor < (FF000F70)>] 3D loaded, re-acquiring mass: 0.000000[03/29/2012 - 10:39:20PM] Throwing actor: [Actor < (FF000F5B)>] mass: 495.000000 dist: 168.228516 massmult: 15.000000 result: 7425.000000 force: 6175.903320[03/29/2012 - 10:39:20PM] Throwing actor: [Actor < (FF000F6D)>] mass: 495.000000 dist: 66.467186 massmult: 15.000000 result: 7425.000000 force: 6931.481445[03/29/2012 - 10:39:20PM] Throwing actor: [Actor < (FF000F64)>] mass: 495.000000 dist: 112.121025 massmult: 15.000000 result: 7425.000000 force: 6592.501465[03/29/2012 - 10:39:20PM] Throwing actor: [Actor < (FF000F6E)>] mass: 495.000000 dist: 122.187210 massmult: 15.000000 result: 7425.000000 force: 6517.760254[03/29/2012 - 10:39:20PM] Throwing actor: [Actor < (FF000F70)>] mass: 100.000000 dist: 259.653076 massmult: 15.000000 result: 1500.000000 force: 1110.520386

Apparently it only gets the mass SOMETIMES, real useful.

Although using it a second time on the same actors seemed to be okay and their mass was updated correctly...
User avatar
Johnny
 
Posts: 3390
Joined: Fri Jul 06, 2007 11:32 am

Post » Wed Jun 20, 2012 9:33 pm

What about GetActorValue("Mass")?
User avatar
FABIAN RUIZ
 
Posts: 3495
Joined: Mon Oct 15, 2007 11:13 am

Post » Wed Jun 20, 2012 6:23 pm

Did you even manage to get it to work on larger animals, like a mammoth? I always get the "npc is not in bleedout" error when I try to do a pushactoraway on them, so I assumed it was impossible to do...
User avatar
Matt Bee
 
Posts: 3441
Joined: Tue Jul 10, 2007 5:32 am

Post » Wed Jun 20, 2012 8:14 pm

Yeah, I got this to work with trolls, never tried a mammoth, suppose I can do that now. The GetMass didn't seem to be very happy though, I had to basically shove it in a while loop that tried to get the mass up 5 times if it was returning zero, to make sure I always returned a mass. The actual AoE aspect of the spell seemed a little buggy. Sometimes if I were in third person nothing would get hit by the AoE so the script wouldn't trigger on anything, and the "area" (Said to be measured in feet) of the spell didn't have any bearing on how far it actually searched for actors to hit, hence why I had the script do a distance check because actors some thousands of units away were being hit by it.
User avatar
Setal Vara
 
Posts: 3390
Joined: Thu Nov 16, 2006 1:24 pm

Post » Wed Jun 20, 2012 1:49 pm

I second trying to use akTarget.GetActorValue("Mass").

You're using a function of ObjectReference on an Actor (akTarget is an actor). Try casting the Actor as an ObjectRefence and use GetMass(), or try the above, and see if that works.
User avatar
Steve Smith
 
Posts: 3540
Joined: Sat Jun 30, 2007 10:47 am

Post » Wed Jun 20, 2012 3:21 pm

I'll try the ActorValue and see if it produces the same result. Actor is derived from ObjectReference, casting it to ObjectReference is irrelevant because it Auto-Casts, considering Actor doesn't have an override for GetMass it's going to use the function from ObjectReference anyway.

Edit: GetActorValue("Mass") always returns 1... That isn't useful at all... Lol
User avatar
Marina Leigh
 
Posts: 3339
Joined: Wed Jun 21, 2006 7:59 pm

Post » Wed Jun 20, 2012 1:43 pm

Mass will always be 0 if target is not in ragdoll state. You have to ForceAddRagdollToWorld() before issuing GetMass() or push them away and wait like 0.1 seconds before asking for mass. What I don't know is if it is neccessary to ForceRemoveRagdollFromWorld() after we get the mass.
User avatar
joseluis perez
 
Posts: 3507
Joined: Thu Nov 22, 2007 7:51 am

Post » Wed Jun 20, 2012 7:32 am

If it works on some things but not others, I agree with trying to place a wait in there... I've found some functions (like enable/disable) take a bit of time before the very next line of code can run something on that object. I've even seen placing a non-wait function between them and it works (as well as wait(0.0)).

eg: If I try to enable a static, then try to translateTo on the next line of code, it returns the 'no3D/parent cell' error. But placing a transTo on a diff object between them allows it to work (as well as a 0.01 wait or even 0.0). I've also seen other functions require this slight delay... so check your Papyrus log for errors to see if anything strange is going on.
User avatar
Stacey Mason
 
Posts: 3350
Joined: Wed Nov 08, 2006 6:18 am


Return to V - Skyrim