Skip to content
18 changes: 11 additions & 7 deletions armory/Sources/armory/logicnode/SetFirstPersonControllerNode.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,21 @@ class SetFirstPersonControllerNode extends LogicNode {
}

override function run(from: Int): Void {
// Script para controlar las var de FirstPersonController...

// Control de las var de FirstPersonController...
// Control FirstPersonController var
var object: Object = inputs[1].get();

// Ajustes de la camara.
// Ajustes de la camara. // Camera settings
var rotationSpeed: Float = inputs[2].get();
var maxPitch: Float = inputs[3].get();
var minPitch: Float = inputs[4].get();
// Ajustes de desplazamiento..
// Ajustes de desplazamiento.. // Move settings
var moveSpeed: Float = inputs[5].get();
var runSpeed: Float = inputs[6].get();


// var bool para activar/desactivar las prop del trait (FirstPersonController)
// var bool to set true/false the trait props (FirstPersonController)
var enableJump: Bool = inputs[7].get();
var allowAirJump: Bool = inputs[8].get();
var canRun: Bool = inputs[9].get();
Expand All @@ -32,20 +33,21 @@ class SetFirstPersonControllerNode extends LogicNode {

if (object == null) return;

// Tomar el Trait desde el objcet(FPController)
// Tomar el Trait desde el object (FPController) // Get trait from (object) and assigned to the var (fpController)
var fpController: armory.trait.FirstPersonController = object.getTrait(armory.trait.FirstPersonController);
if (fpController != null) {

// Ajustes con respecto a la rot de la camara
// Ajustes de la camara // Cam settings
fpController.rotationSpeed = rotationSpeed;
fpController.maxPitch = maxPitch;
fpController.minPitch = minPitch;
// Ajuste de desplazamiento
// Ajuste de desplazamiento // Move settings
fpController.moveSpeed = moveSpeed;
fpController.runSpeed = runSpeed;


// Ajustes de salto, correr, stamina y fariga()
// Settings (run, jump, stamina anad fatigue)
fpController.enableJump = enableJump;
fpController.allowAirJump = allowAirJump;
fpController.canRun = canRun;
Expand All @@ -54,10 +56,12 @@ class SetFirstPersonControllerNode extends LogicNode {

} else {
// Alertar al usuario si es que no tiene el trait asigando al objeto.
// Alert the user if they do not have the trait assigning to the object.
trace("ERROR: The object '" + object.name + "' does not have the FirstPersonController script assigning(assign it from (Object->add trait->bundle)).");
}

runOutput(0);
}

}

66 changes: 66 additions & 0 deletions armory/Sources/armory/logicnode/SetOverheadPersonControllerNode.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package armory.logicnode;

import iron.object.Object;


class SetOverheadPersonControllerNode extends LogicNode {

public function new(tree: LogicTree) {
super(tree);
}

override function run(from: Int): Void {
// Control de las var de OverheadPersonController...
// Control OverheadPersonController var
var objectTrait: Object = inputs[1].get();

// Ajustes de la camara. // Camera settings
var smoothTrack: Bool = inputs[2].get();
var smoothSpeed: Float = inputs[3].get();

// Ajustes de desplazamiento.. // Move setting
var moveSpeed: Float = inputs[4].get();
var runSpeed: Float = inputs[5].get();

// var bool para activar/desactivar las prop del trait (OverheadPersonController)
// var bool to set true/false the trait props (OverheadPersonController)
var enableJump: Bool = inputs[6].get();
var allowAirJump: Bool = inputs[7].get();
var canRun: Bool = inputs[8].get();
var stamina: Bool = inputs[9].get();
var enableFatigue: Bool = inputs[10].get();

if (objectTrait == null) return;

// Tomar el trait del object (ovController). // Get trait from (objectTrait) and assigned to the var (ovController)
var ovController: armory.trait.OverheadPersonController = objectTrait.getTrait(armory.trait.OverheadPersonController);
if (ovController != null) {

// Ajustes del suavizado de la camara
// Setting smoothCamera
ovController.smoothTrack = smoothTrack;
ovController.smoothSpeed = smoothSpeed;
// Ajuste de desplazamiento
// Setting move
ovController.moveSpeed = moveSpeed;
ovController.runSpeed = runSpeed;


// Ajustes de salto, correr, stamina y fariga()
// Settings (run, jump, stamina anad fatigue)
ovController.enableJump = enableJump;
ovController.allowAirJump = allowAirJump;
ovController.canRun = canRun;
ovController.stamina = stamina;
ovController.enableFatigue = enableFatigue;

} else {
// Alertar al usuario si es que no tiene el trait asigando al objeto.
// Alert the user if they do not have the trait assigning to the object..
trace("ERROR: The object '" + objectTrait.name + "' does not have the OverheadPersonController script assigning(assign it from (Object->add trait->bundle)).");
}

runOutput(0);
}

}
46 changes: 25 additions & 21 deletions armory/Sources/armory/trait/FirstPersonController.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ class FirstPersonController extends Trait {
}

var zVec = Vec4.zAxis();

// Control de la rotacion del jugador y la camara con el mouse..
// Control player and camera rotation with the mouse.
function preUpdate() {
if (Input.occupied || body == null) return;
var mouse = Input.getMouse();
var kb = Input.getKeyboard();

// Blooquear/Desbloquear cursor // lock/unlock cursor
if (mouse.started() && !mouse.locked)
mouse.lock();
else if (kb.started("escape") && mouse.locked)
Expand All @@ -112,7 +113,7 @@ class FirstPersonController extends Trait {
function isFatigued():Bool {
return enableFatigue && isFatigueActive;
}

// Comprobar si el jugador esta moviendose y si esta en el suelo // Check if the player is moving and if he is on the ground...
function update() {
if (body == null) return;
var deltaTime:Float = iron.system.Time.delta;
Expand All @@ -132,14 +133,15 @@ class FirstPersonController extends Trait {
}
#end

// Dejo establecido el salto para tener en cuenta la (enableFatigue) si es que es false/true....
// Dejo establecido el salto para tener en cuenta (isFatigued)
// I set the jump to take into account the (isFatigued)
if (isGrounded && !isFatigued()) {
canJump = true;
}
// Saltar con estamina
// Saltar con estamina // Jump with stamina
if (enableJump && kb.started(jumpKey) && canJump) {
var jumpPower = jumpForce;
// Disminuir el salto al 50% si la (stamina) esta por debajo o en el 20%.
// Disminuir el salto al 50% si la (stamina) esta por debajo o en el 20%. // Decrease jump to 50% if stamina is below or at 20%
if (stamina) {
if (staminaValue <= 0) {
jumpPower = 0;
Expand All @@ -151,64 +153,67 @@ class FirstPersonController extends Trait {
if (staminaValue < 0.0) staminaValue = 0.0;
timeSinceStop = 0.0;
}

if (jumpPower > 0) {
body.applyImpulse(new Vec4(0, 0, jumpPower));
if (!allowAirJump) canJump = false;
}
}

// Control de estamina y correr
// Control de estamina y correr // Control of stamina and running
if (canRun && kb.down(runKey) && isMoving) {
if (stamina) {
if (staminaValue > 0.0) {
isRunning = true;
staminaValue -= staDecreasePerSec * deltaTime;
if (staminaValue < 0.0) staminaValue = 0.0;
timeSinceStop = 0.0;
fatigueTimer += deltaTime;
fatigueCooldown = 0.0;
} else {
isRunning = false;
}
} else {
isRunning = true;
timeSinceStop = 0.0;
fatigueTimer += deltaTime;
fatigueCooldown = 0.0;
}
} else {
isRunning = false;
}

// (temporizadores aparte) (fatigue system timers)
if (isRunning) {
timeSinceStop = 0.0;
fatigueTimer += deltaTime;
fatigueCooldown = 0.0;
} else {
timeSinceStop += deltaTime;
fatigueCooldown += deltaTime;
}

// Evitar correr y saltar al estar fatigado...
// Evitar correr y saltar al estar fatigado // Avoid running and jumping when fatigued
if (isFatigued()) {
isRunning = false;
canJump = false;
}

// Activar fatiga después de correr continuamente durante cierto umbral
// Activar fatiga despues de correr continuamente durante cierto umbral
// Activate fatigue after running continuously for a certain threshold
if (enableFatigue && fatigueTimer >= fatigueThreshold) {
isFatigueActive = true;
}

// Eliminar la fatiga despues de recuperarse
// Eliminar la fatiga despues de recuperarse // Eliminate fatigue after recovery (fatRecoveryThreshold)
if (enableFatigue && isFatigueActive && fatigueCooldown >= fatRecoveryThreshold) {
isFatigueActive = false;
fatigueTimer = 0.0;
}

// Recuperar estamina si no está corriendo
// Recuperar estamina si no esta corriendo // Recover stamina if you re not running ()
if (stamina && !isRunning && staminaValue < staminaBase && !isFatigued()) {
if (timeSinceStop >= staRecoverTime) {
staminaValue += staRecoverPerSec * deltaTime;
if (staminaValue > staminaBase) staminaValue = staminaBase;
}
}

// Movimiento
// Movimiento en ejes locales // Movement on local axies
dir.set(0, 0, 0);
if (moveForward) dir.add(object.transform.look());
if (moveBackward) dir.add(object.transform.look().mult(-1));
Expand All @@ -217,15 +222,14 @@ class FirstPersonController extends Trait {

var btvec = body.getLinearVelocity();
body.setLinearVelocity(0.0, 0.0, btvec.z - 1.0);

// Movement speed control (final) (run and fatigued when are true/false)
if (isMoving) {
var dirN = dir.normalize();
var baseSpeed = moveSpeed;
if (isRunning && moveForward) {
baseSpeed = runSpeed;
}
var currentSpeed = isFatigued() ? baseSpeed * fatigueSpeed : baseSpeed;
var currentSpeed = isFatigued() ? baseSpeed * fatigueSpeed : baseSpeed;
dirN.mult(currentSpeed * deltaTime);
body.activate();
body.setLinearVelocity(dirN.x, dirN.y, btvec.z - 1.0);
Expand Down
Loading