Search Unity

Noob Rotation

Discussion in 'Scripting' started by DanSingh, May 30, 2016.

  1. DanSingh

    DanSingh

    Joined:
    Feb 5, 2015
    Posts:
    98
    Greeting,
    I have recently been working on a game that applies the first person view concept, and I was coding in my character movement, and I know this is a noob question, but I'm stuck, I got my character to move but when rotating the mouse, the character does not go in the indicated direction. I was using a character controller at first to fix this issue, but the Character controller wasn't ideal with my other assets. I hope this was clear enough, please help.
    Code (CSharp):
    1. //Mouse Movement
    2.  
    3.         //X direction
    4.         rotLR = Input.GetAxisRaw("Mouse X") * mouseSense;
    5.         transform.Rotate (0f, rotLR, 0f);
    6.  
    7.         //Y Direction
    8.         vertRot -= Input.GetAxisRaw("Mouse Y") * mouseSense;
    9.         vertRot = Mathf.Clamp (vertRot, -yTopRange, yBottomRange);
    10.         cam.transform.localRotation = Quaternion.Euler (vertRot, 0f, 0f);
    11.    
    12.         if (isWalking) {
    13.  
    14.             // Set the movement vector based on the axis input.
    15.             movemt.Set (h, 0f, v);
    16.  
    17.             // Normalise the movement vector and make it proportional to the speed per second.
    18.             movemt = movemt.normalized * tempSpeed * Time.deltaTime;
    19.  
    20.             // Move the player to it's current position plus the movement.
    21.             rigidBody.MovePosition (transform.position + movemt);
    22.  
    23.             //Using with CC don't want
    24.             /*Vector3 speed = new Vector3 (h, vertVel, v);
    25.             speed = transform.rotation * speed;
    26.  
    27.             cc.Move (speed * Time.deltaTime);*/
    28.         }
     
  2. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    You can simply get a vector pointing in the characters direction by using transform.forward nd then you can multiple the horizontal input with this one. Same with sideways vector, but with transform.right. If you add these two together, you get the movenent vector
     
  3. DanSingh

    DanSingh

    Joined:
    Feb 5, 2015
    Posts:
    98
    I understand what your getting at but I can't figure out how to apply it, do I also use Quaterion.LookRotation?
     
  4. DanSingh

    DanSingh

    Joined:
    Feb 5, 2015
    Posts:
    98
    Actually I figured it out, thanks, however My controls are weird, when I intentional move forward I move right or left.
     
  5. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Yeah, instead of transform.forward times horizontal, use vertical instead
     
  6. DanSingh

    DanSingh

    Joined:
    Feb 5, 2015
    Posts:
    98
    Yeah, As soon as I figured it out, you replied back, thanks so much.
     
  7. DanSingh

    DanSingh

    Joined:
    Feb 5, 2015
    Posts:
    98
    Actually one more question, in monodevelop when I open a new curly bracket, it auto indents itself
    to something like this
    Code (CSharp):
    1. if(people){
    2. }
    and I hate brackets like that i want it to not indent it for me like that. I want to to do this
    Code (CSharp):
    1. if(people)
    2. {
    3. }
    Do you know how to fix that?
     
  8. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    You'll have to dig through the preferences menu in MD - you're looking for "formatting" somewhere. You can both have it automatically create the kind of brackets you want, or just turn off the automatic indentation altogether.

    Also your view on where brackets go are heretical.
     
  9. gorbit99

    gorbit99

    Joined:
    Jul 14, 2015
    Posts:
    1,350
    Am I weird if I use these:
    Code (CSharp):
    1. one line {
    2.    two line
    3. }
    in JScript and others, whilst I use:
    Code (CSharp):
    1. one line
    2. {
    3.    two lines
    4. }
    in C# and
    Code (CSharp):
    1. IF (
    2.    i feel retarded when using this one
    3. )
    in batch and sometimes
    Code (CSharp):
    1. GL.Begin();
    2. {
    3.    Just for the indentation
    4. }
    5. GL.End();
    for stuff, that uses a start-end thingy, without auto indentation (GL, xna spritebatches, etc.)?