Help with rotation script please :)

Hey everyone,

This is my first post on the unity forums so I apologise if I don’t sound like I know what I’m doing.

I am using a first person camera that can look around. I would like to position a game object (currently I am using a sphere) at a “x” distance away from the center of the screen in the opposite direction that the camera has rotate in. For example, when I look towards the left, the sphere will be placed to the right of the center of the screen at “x” distance away.

Here is the solution that I have tried:

(psuedo code)

void update
get current rotation of camera = position1
}

void LateUpdate
get current rotation of camera = position2

cast ray from position1 to position2

extend the ray “x” distance away

set position of sphere to the endpoint of ray
}

Does anyone know of a way to implement this?

Thank you so much for anyone who took the time

Hi joshua1232,

You have given some details in your question which is good but maybe a little context would help.

Is this a UI element (for example a button) or an in-game item (such as a waypoint marker graphic, for example)?

Are you using a 2D top down view onto a simple plane, or a more detailed 3D environment?

What does ‘cursor’ mean in the context of your game? Is your camera moving or is it static?

Also, if you could post some code of something you have already tried, that may prove helpful as well. :slight_smile:

Hey Doug,
Thank you so much for your reply. I will try to put in as much detail as I can for this post. Hopefully I can get this problem solved soon. Thanks so much again.