Switching postion with Object by clicking it

Hey, I´m curently runging into a wall here. Imanaged to make a moveable player camera by useing this script:

{
public float mouseSensitivity = 100f;

public Transform playerBody;

float xRotation = 0f;
public Vector2 turn;
public float sensitivity = 50;
public Vector3 deltaMove;
public float speed = 1;

// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}

// Update is called once per frame
void Update()
{
turn.x += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
turn.y = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
xRotation -= turn.y;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRotation, turn.x, 0);

}
}

dose someone have an idea to acomplish that, beacause im lost.

Please use code-tags when posting code.

Thanks!

I edited it :slight_smile:

So if I read you, you’re running into a wall, but you have a movable player camera, but you are lost.

I’m not really sure how to even respond. Perhaps this is helpful to you:

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, especially any errors you see
    - links to documentation you used to cross-check your work (CRITICAL!!!)

Not quite. Check again. It matters because there are no line numbers above so nobody can talk about the code.

If you post a code snippet, ALWAYS USE CODE TAGS:

How to use code tags: https://discussions.unity.com/t/481379

Thanks for trying but the above isn’t code tags, it’s just some block formatting. The link shows you how. This is what it’d look like:

public class mouselook : MonoBehaviour
{
   public float mouseSensitivity = 100f;
   public Transform playerBody;
   float xRotation = 0f;
   public Vector2 turn;
   public float sensitivity = 50;
   public Vector3 deltaMove;
   public float speed = 1;

   // Start is called before the first frame update
   void Start()
   {
       Cursor.lockState = CursorLockMode.Locked;
   }

   // Update is called once per frame
   void Update()
   {
       turn.x += Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
       turn.y = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;
       xRotation -= turn.y;
       xRotation = Mathf.Clamp(xRotation, -90f, 90f);
       transform.localRotation = Quaternion.Euler(xRotation, turn.x, 0);
   }
}

As is very common on the forums, you didn’t actually say what you expect to happen and what wasn’t working!

The above, albeit a bit basic, would rotate the camera around in a FPS-ish way.