Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- updateFPSControls(transform) {
- if (Game.Input.Key.rightArrow.down) {
- this.moving.right = true;
- this.moving.left = false;
- this.moving.pressedX = true;
- Game.camera.rigidbody.acceleration.x = this.accelerationRate;
- }
- else if (Game.Input.Key.leftArrow.down) {
- this.moving.left = true;
- this.moving.right = false;
- this.moving.pressedX = true;
- Game.camera.rigidbody.acceleration.x = -this.accelerationRate;
- }
- else {
- this.moving.pressedX = false;
- }
- if (Game.Input.Key.upArrow.down) {
- this.moving.forward = true;
- this.moving.back = false;
- this.moving.pressedZ = true;
- Game.camera.rigidbody.acceleration.z = -this.accelerationRate;
- }
- else if (Game.Input.Key.downArrow.down) {
- this.moving.back = true;
- this.moving.forward = false;
- this.moving.pressedZ = true;
- Game.camera.rigidbody.acceleration.z = this.accelerationRate;
- }
- else {
- this.moving.pressedZ = false;
- }
- }
- updateFPSMovement (transform) {
- if (this.moving.pressedZ) {
- // Moving Forward
- if (this.moving.forward) {
- this.velocity.z += this.acceleration.z;
- if (this.velocity.z <= -this.maxVelocity.z) {
- this.velocity.z = -this.maxVelocity.z;
- }
- }
- // Moving Forward
- if (this.moving.back) {
- this.velocity.z += this.acceleration.z;
- if (this.velocity.z >= this.maxVelocity.z) {
- this.velocity.z = this.maxVelocity.z;
- }
- }
- }
- else {
- if (this.moving.forward) {
- if (this.velocity.z < 0) {
- this.velocity.z -= this.acceleration.z;
- // Reached Desintation
- if (this.velocity.z >= 0) {
- this.velocity.z = 0;
- this.moving.forward = false;
- }
- }
- else {
- this.velocity.z += this.acceleration.z;
- // Reaached Destination
- if (this.velocity.z <= 0) {
- this.velocity.z = 0;
- this.moving.forward = false;
- }
- }
- }
- if (this.moving.back) {
- if (this.velocity.z > 0) {
- this.velocity.z -= this.acceleration.z;
- // Reached Desintation
- if (this.velocity.z <= 0) {
- this.velocity.z = 0;
- this.moving.back = false;
- }
- }
- else {
- this.velocity.z += this.acceleration.z;
- // Reaached Destination
- if (this.velocity.z >= 0) {
- this.velocity.z = 0;
- this.moving.back = false;
- }
- }
- }
- }
- if (this.moving.pressedX) {
- // Moving Right
- if (this.moving.right) {
- this.velocity.x += this.acceleration.x;
- if (this.velocity.x >= this.maxVelocity.x) {
- this.velocity.x = this.maxVelocity.x;
- }
- }
- // Moving Left
- if (this.moving.left) {
- this.velocity.x += this.acceleration.x;
- if (this.velocity.x <= -this.maxVelocity.x) {
- this.velocity.x = -this.maxVelocity.x;
- }
- }
- }
- // Not pressed
- else {
- if (this.moving.right) {
- if (this.velocity.x < 0) {
- this.velocity.x += this.acceleration.x;
- // Reached Destination.
- if (this.velocity.x >= 0) {
- this.velocity.x = 0;
- this.moving.right = false;
- }
- }
- else {
- this.velocity.x -= this.acceleration.x;
- if (this.velocity.x <= 0) {
- this.velocity.x = 0;
- this.moving.right = false;
- }
- }
- }
- if (this.moving.left) {
- if (this.velocity.x < 0) {
- this.velocity.x -= this.acceleration.x;
- // Reached Desintation
- if (this.velocity.x >= 0) {
- this.velocity.x = 0;
- this.moving.left = false;
- }
- }
- else {
- this.velocity.x += this.acceleration.x;
- // Reaached Destination
- if (this.velocity.x <= 0) {
- this.velocity.x = 0;
- this.moving.left = false;
- }
- }
- }
- }
- transform.position.x += this.velocity.x * Game.Time.step;
- transform.position.y += this.velocity.y * Game.Time.step;
- transform.position.z += this.velocity.z * Game.Time.step;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement