- Home /
Transform/Quaternion affecting collider?
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!
Answer by ForrestS · Oct 08, 2013 at 06:23 PM
I fixed my problem. I needed to use rigidbody.rotation instead of transform.rotation since all of my movement is being done via the rigidbody. The transform.rotation line was turning the collider back on because transform is linked to the collider, right?
Your answer
Follow this Question
Related Questions
Why is this rotation acting odd? 0 Answers
Efficiency of transform.forward, up, and right 2 Answers
Connecting transform with Vector3 4 Answers
Quaternions acting up 1 Answer