I have a script that rotates the player in the direction he is firing; it’s a top-down sort of game, and the player just faces whichever way he or she is firing.
I have another script that deals with controls, and also gives the player a brief invulnerability period on a new life. The way this invulnerability period works is is simply deactivating the collider on the object until the period is over.
For some reason, when I’m firing during the invulnerability period, the collider turns back on. Only when a fire button is pressed - when I stop, the collider turns back off.
I’ve deduced it’s something to do with rotate script, as when I deactivate the script, the problem is fixed. I just can’t figure out what it is in the rotate script that’s causing it, or whether it’s interfering with another script.
Here is the rotate script:
using UnityEngine;
using System.Collections;
public class RotatePlayer : MonoBehaviour {
public float rotateSpeed = 3.0f;
void Start () {
//rotation = Quaternion.LookRotation ( lookRotation );
}
// Update is called once per frame
void Update () {
Vector3 fireDirection = new Vector3 ( Input.GetAxis ( "FireHorizontal" ), Input.GetAxis ( "FireVertical" ), 0 );
if ( Input.GetKey ( KeyCode.UpArrow ) || Input.GetKey (KeyCode.DownArrow) || Input.GetKey (KeyCode.LeftArrow) || Input.GetKey (KeyCode.RightArrow)) {
transform.rotation = Quaternion.RotateTowards ( Quaternion.LookRotation ( transform.forward, transform.up ), Quaternion.LookRotation ( fireDirection, transform.up ), Mathf.Rad2Deg * rotateSpeed * Time.deltaTime );
}
}
}
I can comment out the transform.rotation line and the collider stays off. I’m wondering if I’m messing with the collider somehow in that line?
Thanks!