Question by
InternetWhovian · Nov 01, 2016 at 11:02 PM ·
c#fpsspeedfirst person shooterfirstpersonshooter
C# FPS Speed Boost
I am making an Multiplayer FPS game with elements in it for a school project, and I can't figure out how to make a speed boost that will put a 2x speed modifier on the player, which will be applied to one of the elements. Please help in any way possible. Thanks.
Character Controller:
using UnityEngine; using System.Collections;
public class PlayerController : MonoBehaviour {
NetworkCharacter netChar;
// Use this for initialization
void Start() {
netChar = GetComponent<NetworkCharacter>();
}
// Update is called once per frame
void Update() {
// WASD forward/back & left/right movement is stored in "direction"
netChar.direction = transform.rotation * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
// This ensures that we don't move faster going diagonally
if (netChar.direction.magnitude > 1f) {
netChar.direction = netChar.direction.normalized;
}
if (Input.GetButton("Jump")) {
netChar.isJumping = true;
}
else {
netChar.isJumping = false;
}
AdjustAimAngle();
if (Input.GetButton("Fire1")) {
// Player wants to shoot...so. Shoot.
netChar.FireWeapon(Camera.main.transform.position, Camera.main.transform.forward);
}
}
void AdjustAimAngle() {
Camera myCamera = this.GetComponentInChildren<Camera>();
if (myCamera == null) {
Debug.LogError("Why doesn't my character have a camera? This is an FPS!");
return;
}
float aimAngle = 0;
if (myCamera.transform.rotation.eulerAngles.x <= 90f) {
// We are looking DOWN
aimAngle = -myCamera.transform.rotation.eulerAngles.x;
}
else {
aimAngle = 360 - myCamera.transform.rotation.eulerAngles.x;
}
netChar.aimAngle = aimAngle;
}
}
Comment