I’m currently making a little game about a ball, the ball have a weapon/tool that can turn around the player depending on where he is looking at.
But right now i’m making a portal gun, a orange one, and a blue one, the orange one is suposed to be to the left of the ball instead of the right like the blue one.
I kinda found some fix like changing the model rotation in blender but i feel like it a really wrong way to do it.
Right now what i do is i use 2 script one for the “portal gun” and one for the “aiming where i’m looking at” part:
Portal gun
void Update()
{
//This is used to get the information of where i'm hitting and call the void to
instantiate a portal
if (Input.GetKeyDown(KeyCode.Mouse0))
{
rayOrange = new Ray(Camera.transform.position,
Camera.transform.forward);
CheckForColliders();
}
//used to place the portal gun at the player position
transform.position = player.transform.position;
//used to Rotate the weapon the right direction
transform.Rotate(Vector3.forward, 180);
{
Aim where i’m looking at
void Update()
{
cameraRaycast = new Ray(Camera.transform.position,
Camera.transform.forward);
if (Physics.Raycast(cameraRaycast, out RaycastHit cameraRaycastHit))
{
transform.LookAt(cameraRaycastHit.point, Vector3.up);
}
else
{
transform.rotation = Camera.transform.rotation;
}
}
transform.Rotate
should make it spin around the player but when i’m using transform.LookAt
i think it OverRide it and do not make it spin but still go where i’m aiming at with the right rotation, which is what i want but feel like there could be a lot of problem with it and and that it will just bite me in the ankle back one day.
And no i tried using transform.rotation
and it just lock it in place and can’t use the “aim where i’m looking at” part so is it how i’m suposed to do it or should i do it in a other way?