Skip to main content
added 50 characters in body
Source Link
Samuel Fyckes
  • 322
  • 1
  • 5
  • 18

I want my character to walk around sphere like a planet, so in my script I rotate it according to the normal of a raycast and I also rotate my character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotation gets closer to 180, the X and Z rotation start jittering.

    RaycastHit hit;
    Vector3 rayStart = new Vector3(0,-1,0) + transform.position;
    if (Physics.Raycast(rayStart, -transform.up, out hit, Mathf.Infinity))
    {

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);
    }

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ? Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.

I want my character to walk around sphere like a planet, so in my script I rotate it according to the normal of a raycast and I also rotate my character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotation gets closer to 180, the X and Z rotation start jittering.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ? Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.

I want my character to walk around sphere like a planet, so in my script I rotate it according to the normal of a raycast and I also rotate my character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotation gets closer to 180, the X and Z rotation start jittering.

    RaycastHit hit;
    Vector3 rayStart = new Vector3(0,-1,0) + transform.position;
    if (Physics.Raycast(rayStart, -transform.up, out hit, Mathf.Infinity))
    {

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);
    }

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ? Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.

added 50 characters in body
Source Link
Samuel Fyckes
  • 322
  • 1
  • 5
  • 18

I have a camera onwant my character. The camera, which as a script to look verticaly, is the child of my player object, which I want to walk on aaround sphere like a planet and as the, so in my script I rotate it according to look horizontallythe normal of a raycast and I also rotate itselfmy character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotationsrotation gets closer to 180, the X and Z rotation start jittering and causes my camera to shake.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ? Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.

I have a camera on my character. The camera, which as a script to look verticaly, is the child of my player object, which I want to walk on a sphere like a planet and as the script to look horizontally and rotate itself. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotations gets closer to 180, the X and Z rotation start jittering and causes my camera to shake.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ?

I want my character to walk around sphere like a planet, so in my script I rotate it according to the normal of a raycast and I also rotate my character on the Y axis when I look around with the mouse. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotation gets closer to 180, the X and Z rotation start jittering.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ? Both the line to rotate the character according to the camera and the one to rotate it around the planet work individually, but not together.

added 50 characters in body
Source Link
Samuel Fyckes
  • 322
  • 1
  • 5
  • 18

I have a camera on my character. The The camera, which as a script on it movesto look verticaly, is the camerachild of my player object, which I want to walk on a sphere like a planet and as the y axisscript to look up and down,horizontally and I rotate the character on the y axis so it rotates with the cameraitself. When When press play, I can look in any direction in front of me, left and right, but when my characters Y rotations gets closer to 180, the X and Z rotation start jittering and causes my camera to shake.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ?

I have a camera on my character. The script on it moves the camera on the y axis to look up and down, and I rotate the character on the y axis so it rotates with the camera. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotations gets closer to 180, the X and Z rotation start jittering and causes my camera to shake.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ?

I have a camera on my character. The camera, which as a script to look verticaly, is the child of my player object, which I want to walk on a sphere like a planet and as the script to look horizontally and rotate itself. When press play, I can look in any direction in front of me, left and right, but when my characters Y rotations gets closer to 180, the X and Z rotation start jittering and causes my camera to shake.

        Vector3 rotation = new Vector3(Quaternion.LookRotation(hit.normal).x,0, Quaternion.LookRotation(hit.normal).z);
        transform.Rotate(0, Input.GetAxis("Mouse X") * sensitivityX, 0);
        transform.eulerAngles = new Vector3(rotation.x,transform.eulerAngles.y,rotation.z);

I also tried transform.rotation = Quaternion.Euler(rotation.x,transform.eulerAngles.y,rotation.z); but it changes nothing. If I remove the 3rd line, it works, so i'm guessing i'm assigning the rotation the wrong way ?

Source Link
Samuel Fyckes
  • 322
  • 1
  • 5
  • 18
Loading