transform.rotation problem.

Hello. OnTriggerEnter I need to rotate my player 180 degrees(upside down).
I tried something like: OnTriggerEnter boolean = true, then in FixUpdate - if bool true → transform.rotation = Quaternion.Euler(180,transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z); but nothing happen when the bool becomes true…

Your post is hard to read.
Use code tags to format your code.
If you present a decent question its more likely you’ll get a decent answer.

Sorry, I’ll try to explain more detailed. I need to rotate my rigidbody controller upside down when some boolean comes true:

if (somebool){
     transform.rotation = Quaternion.Euler(180, 0, 0);
}

But its not working…

Looks ok to me.
You should try to put a Debug.Log(somebool) in there to see if that code actually gets hit.

Its not work at all. I dont know why, but this line “Quaternion.Euler(180, 0, 0);” makes the player rotation only if I using it in Start or Awake function.
In Update or OnTriggerEnter its just do nothing.

I also tried to use “transform.eulerAngles” insteed of “Quaternion.Euler” :

transform.eulerAngles = Vector3(180, 0, 0);

But its working only in Awake or Start function too. I cant understand it, help me please.

I think the problem is somewhere in the player script but where?

var speed = 8.0;
var gravity = 20;
var maxVelocityChange = 10.0;
var inAirControl = 0.1;
var canJump = true;
var wallJump = true;
var jumpHeight = 2.0;
var grounded = false;
private var groundVelocity : Vector3;
private var capsule : CapsuleCollider;
  
  
@script RequireComponent(Rigidbody, CapsuleCollider)
function Awake (){
	rigidbody.freezeRotation = true;
	rigidbody.useGravity = false;
	capsule = GetComponent(CapsuleCollider);
//      transform.eulerAngles = Vector3(180, 0, 0);   //WORKS FINE
	}  	
  	
function Update (){
Debug.Log (transform.rotation.x);
//transform.eulerAngles = Vector3(180, 0, 0);    // DOESNT WORK
}
 
function FixedUpdate (){ 
                                                                      
//              if (grounded){
          // Calculate how fast we should be moving
          var targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
          targetVelocity = transform.TransformDirection(targetVelocity);
          targetVelocity *= speed;
          // Apply a force that attempts to reach our target velocity
          var velocity = rigidbody.velocity;
          var velocityChange = (targetVelocity - velocity) + groundVelocity;
          velocityChange.x = Mathf.Clamp(velocityChange.x, -maxVelocityChange, maxVelocityChange);
          velocityChange.z = Mathf.Clamp(velocityChange.z, -maxVelocityChange, maxVelocityChange);
          velocityChange.y = 0;
          rigidbody.AddForce(velocityChange, ForceMode.VelocityChange);
          
          // Jump
          if (grounded){
          	  if (canJump  wallJump  Input.GetButton("Jump")){
              	rigidbody.velocity = Vector3(velocity.x, CalculateJumpVerticalSpeed(), velocity.z);
          }
         
          grounded = false;
      }                          
      else{
          // Add in air

          targetVelocity = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));

          targetVelocity = transform.TransformDirection(targetVelocity) * inAirControl;             

          rigidbody.AddForce(targetVelocity, ForceMode.VelocityChange);

      }
      
      // We apply gravity manually for more tuning control
      rigidbody.AddForce(Vector3 (0, -gravity * rigidbody.mass, 0));	        
  }

  function TrackGrounded (col : Collision){
  	  capsule = GetComponent(CapsuleCollider);
      var minimumHeight = capsule.bounds.min.y + capsule.radius;
      for (var c : ContactPoint in col.contacts){
          if (c.point.y < minimumHeight - 0.2){
              if (col.rigidbody)
                  groundVelocity = col.rigidbody.velocity;
              else
                  groundVelocity = Vector3.zero;
              grounded = true;
          }
      }   
  }

  function OnCollisionStay (col : Collision){
      TrackGrounded (col);
  }

  function OnCollisionEnter (col : Collision){
  	TrackGrounded (col);
	}
     
     
  function CalculateJumpVerticalSpeed (){
      // From the jump height and gravity we deduce the upwards speed
      // for the character to reach at the apex.
      return Mathf.Sqrt(2 * jumpHeight * gravity);
  }

disable mouseLook script.

I think It might be working to using Quaternion like this :

But I need mouseLook to work like usually :frowning:

It works, but in this way I cant look around, only up and down…

Looks like I should change something in the mouseLook script to make it work properly, but what?

@script AddComponentMenu ("Camera-Control/Mouse Look")
enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
var axes = RotationAxes.MouseXAndY;
var sensitivityX : float = 15;
var sensitivityY : float = 15;

var minimumX : float = -360;
var maximumX : float = 360;

var minimumY : float = -60;
var maximumY : float = 60;

var rotationX : float = 0;
var rotationY : float = 0;

private var originalRotation : Quaternion;

function Update () {
	if (axes == RotationAxes.MouseXAndY) {
		rotationX += Input.GetAxis("Mouse X") * sensitivityX;
		rotationY += Input.GetAxis("Mouse Y") * sensitivityY;

		rotationX = ClampAngle (rotationX, minimumX, maximumX);
		rotationY = ClampAngle (rotationY, minimumY, maximumY);
		
		var xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
		var yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
		
		transform.localRotation = originalRotation * xQuaternion * yQuaternion;
	}
	else if (axes == RotationAxes.MouseX) {
		rotationX += Input.GetAxis("Mouse X") * sensitivityX;
		rotationX = ClampAngle (rotationX, minimumX, maximumX);

		xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
		transform.localRotation = originalRotation * xQuaternion;
	}
	else {
		rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
		rotationY = ClampAngle (rotationY, minimumY, maximumY);

		yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
		transform.localRotation = originalRotation * yQuaternion;
	}
}

function Start () {
	if (rigidbody)
		rigidbody.freezeRotation = true;
	originalRotation = transform.localRotation;
}

static function ClampAngle (angle : float, min : float, max : float) : float {
	if (angle < -360.0)
		angle += 360.0;
	if (angle > 360.0)
		angle -= 360.0;
	return Mathf.Clamp (angle, min, max);
}

Solved

Nothing annoys me more on the internet then “SOLVED” posts.

Why don’t you post the solution that you came up with instead of just saying solved, I am sure at some point in time someone will find this thread and face the same problem.

Hey I cured cancer! SOLVED.

Yes, I am that person that was looking for the solution. What a letdown. Oh well, I’ll keep looking . . .