Force stop of the player during weapon firing (resolved)
by 000 · in Torque 3D Beginner · 10/20/2012 (11:58 pm) · 3 replies
I have a heavy duty weapon that I'd like to force the player to stop all movement while firing. Is there a stop player movement function I can call during the weapon fire to do this?
#2
On the other hand, it'd be a simple and helpful exercise to implement a console method that stops a Player from moving. You could basically mimic AIPlayer's setMoveSpeed, but make it networked. All player input gets multiplied by this value in Player::updateMove, and you just set it to 0 to stop all movement.
Heck, here you go! This commit moves mMoveSpeed from AIPlayer to Player, where it will affect player inputs. I also changed canJump() and canJetJump() so that they return false if your move speed is 0. With these changes, you can do
10/22/2012 (2:23 am)
As that solution is client-side, it isn't secure if you have any serious hackers looking at your game. You'd need to stop the player on the server to be effective, and there's not any default way to do that as far as I'm aware, short of something crazy like disconnecting the client from their player (which doesn't work as you presumably want them to be able to aim), or mounting the Player to a temporary object (which may also not even work - I was doing that and ran into all sorts of collision errors when unmounting).On the other hand, it'd be a simple and helpful exercise to implement a console method that stops a Player from moving. You could basically mimic AIPlayer's setMoveSpeed, but make it networked. All player input gets multiplied by this value in Player::updateMove, and you just set it to 0 to stop all movement.
Heck, here you go! This commit moves mMoveSpeed from AIPlayer to Player, where it will affect player inputs. I also changed canJump() and canJetJump() so that they return false if your move speed is 0. With these changes, you can do
%player.setMoveSpeed(0);on the server to freeze a Player.
#3
11/04/2012 (10:15 pm)
Thanks Dan and Lukas!
Torque Owner Lukas Joergensen
WinterLeaf Entertainment
This is the two function I use to pause and continue movement:
function mvPause() { $mvUpAction = 0; $mvDownAction = 0; $mvLeftAction = 0; $mvRightAction = 0; $mvForwardAction = 0; $mvBackwardAction = 0; $moving = 0; } function mvContinue(%speed) { $mvUpAction = $oldUpAction; $mvDownAction = $oldDownAction; $mvLeftAction = $oldLeftAction; $mvRightAction = $oldRightAction; $mvForwardAction = $oldForwardAction; $mvBackwardAction = $oldBackwardAction; $moving = 1; }Called on the client ofc.
This is the functions in my commands.cs:
function clientCmdBeginCast(%timer, %anim, %spell) { if(%timer $= "") %timer = 2000; mvPause(); schedule(%timer, 0, "CastDone", %spell); commandToServer('SpellAnimation', %anim); } function CastDone(%spell) { mvContinue(1); commandToServer('SpellAnimationDone', %spell); }mvContinue should pass the players speed as an argument.The moveleft, right forward and backward have to be edited aswell to make it work. This is taken from my resource:
//------------------------------------------------------------------------------ // Movement Keys //------------------------------------------------------------------------------ $movementSpeed = 1; // m/s // Added this $moving = 1; // Edited all these move functions function moveleft(%val) { $oldLeftAction = %val * $movementSpeed; if($moving) { $mvLeftAction = $oldLeftAction; } } // Edited all these move functions function moveright(%val) { $oldRightAction = %val * $movementSpeed; if($moving) { $mvRightAction = $oldRightAction; } } // Edited all these move functions function moveforward(%val) { $oldForwardAction = %val * $movementSpeed; if($moving) { $mvForwardAction = $oldForwardAction; } } // Edited all these move functions function movebackward(%val) { $oldBackwardAction = %val * $movementSpeed; if($moving) { $mvBackwardAction = $oldBackwardAction; } }Tell me if it works for you!