Stopping the player from moving while attacking

Post » Tue Jun 19, 2012 8:18 am

I'm trying to prevent the player (and theoretically NPCs as well) from moving while in an attack animation and I'm looking for ideas on how to implement this. I am able to detect when the player is attacking with the IsAttacking conditional and prevent them from moving if they perform an attack from a stationary position by reducing their speedmult to 1, but this has a rather odd effect on the other attack animations. Basically, if the player initiates an attack while moving, the reduction in speedmult will prevent them from freely moving with the controls, but they will keep moving in the direction of the attack at normal speed for the remainder of the animation, and can even continue moving in this way indefinitely by attacking repeatedly.

I'm just wondering if anyone can think of a way to prevent that from happening.
User avatar
Arrogant SId
 
Posts: 3366
Joined: Sat May 19, 2007 11:39 am

Post » Tue Jun 19, 2012 10:01 am

Quite by accident, I found that that the "translate" script methods - TranslateTo, TranslateToRef, etc. - effectively "pin" the target until the translation is complete. You could try TranslateTo on the actor, giving X,Y,Z coordinates that are the same as his current coordinates.
TargetActor.TranslateTo(TargetActor.X, TargetActor.Y, TargetActor.Z,...)

I've used this on NPCs and they continue to animate, but don't move anywhere. The catch is that it can look silly, especially if you don't "unpin" them at the right time with TargetActor.StopTranslation().
User avatar
james reed
 
Posts: 3371
Joined: Tue Sep 18, 2007 12:18 am

Post » Tue Jun 19, 2012 12:46 pm

I'm trying to prevent the player (and theoretically NPCs as well) from moving while in an attack animation and I'm looking for ideas on how to implement this. I am able to detect when the player is attacking with the IsAttacking conditional and prevent them from moving if they perform an attack from a stationary position by reducing their speedmult to 1, but this has a rather odd effect on the other attack animations. Basically, if the player initiates an attack while moving, the reduction in speedmult will prevent them from freely moving with the controls, but they will keep moving in the direction of the attack at normal speed for the remainder of the animation, and can even continue moving in this way indefinitely by attacking repeatedly.

I'm just wondering if anyone can think of a way to prevent that from happening.
The effect you obtained is better than what you want to obtain. If you stop advancing when you launch an attack there won't be any way of actually reaching with your weapons NPCs going backwards (archers and mages mainly). If you managed to avoid the blow being redirected on the run, you have already done things realistic enough.
User avatar
mike
 
Posts: 3432
Joined: Fri Jul 27, 2007 6:51 pm


Return to V - Skyrim