Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Vector3.left Switch Camera alternative

Discussion in 'Scripting' started by gudula, Oct 13, 2015.

  1. gudula

    gudula

    Joined:
    May 20, 2015
    Posts:
    125
    Hi

    Is there any method to having used Vector3.left on an object to move it left and then switch camera view on it to the opposite 3d side of the objects and then not move it to the right with Vector3.left.
    What do you do?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,745
    If I can attempt to rephrase what you're asking, since it's not entirely clear to me: You currently have a control that moves a character to the left in world space, what you want to do is have him move to the left based on whatever the direction is the camera is facing. Is that about right?
     
  3. gudula

    gudula

    Joined:
    May 20, 2015
    Posts:
    125
    Its complicated to explain what I have but I can tell you Im playing with this function
    Code (csharp):
    1. Vector3 selectleft = highlighted.transform.TransformDirection(Vector3.left);
    2. if (Physics.Raycast(highlighted.transform.position, selectleft, out hit))
    3.  
    and when I goto the opposite north side of the screen it acts like RIGHT instead of left. It shoot the raycast to the wrong side I think.
    Not sure what to use, Im beginner with Unity3d.
     
  4. gudula

    gudula

    Joined:
    May 20, 2015
    Posts:
    125
    Camera.main.transform.right
    This is what Im looking for.
     
    Last edited: Oct 14, 2015
  5. gudula

    gudula

    Joined:
    May 20, 2015
    Posts:
    125
    Camera.main.transform.down Does not work

    Right seems to work and left dont work. Any ideas?
     
  6. Raminul

    Raminul

    Joined:
    Oct 11, 2015
    Posts:
    8
    If I understand correctly, You could make a Vector3 called Right, and add in the values that make it the opposite of Vector3.left, seperating the two. I'm pretty much a newb, though, so I might be talking out of my butt. But I think that should work if I understood correctly what you're trying to accomplish here.
     
    Last edited: Oct 14, 2015
  7. gudula

    gudula

    Joined:
    May 20, 2015
    Posts:
    125
    I found an answer but funny to leave out left and down
    -Camera.main.transform.left
    you can use minus sign to get opposite.
     
  8. Raminul

    Raminul

    Joined:
    Oct 11, 2015
    Posts:
    8
    Glad you figured it out! :)

    It's always fun to make things work, I managed to figure out how to make a first person cam that finds the target, takes its position and makes it a parent to the camera without the typical public Transform myTarget; stuff, also managed to make it so the player is always facing the cam's direction. That was a pain... but i figured it out all on my own :) transform.eulerAngles was the key.

    Also managed to smoothen the mouse movement with Mathf.SmoothDamp though. Was a blast learning to do all that! :) Simple stuff, but still. It's an accomplishment nevertheless.

    Anyways, have fun with your future projects.