Player cannot rotate for some reason :/

I have tried multiple ways of getting the player to rotate but i cannot seem to get it to rotate here is the code though.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Cell : Photon.MonoBehaviour {

    public Camera ourCamera ;

    public float Speed ;

    private Vector3 Target ;

    public float degreesPerSecond;


    void Awake()
    {
        photonView.RPC ("ChangeMyName", PhotonTargets.AllBuffered, PhotonNetwork.playerList.Length.ToString ());
    }

    [PunRPC]

    void ChangeMyName(string myNewName)
    {
        gameObject.transform.name = myNewName;
    }

    void Start ()
    {

        // if ourCamera is null then set the Main Camera to the variable ourCamera
        if (photonView.isMine)
        {
            ourCamera = Camera.main ;
        }


    }

    void Update ()
    {
        if (photonView.isMine)
        {//        DrawRay ();
            Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);

            Target.z = transform.position.z;
            Quaternion rotation = Quaternion.Euler (new Vector3 (30, 0, 0));
            transform.position = Vector3.MoveTowards (transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
        }
    }






}

Just 1 small issue with your code…
tiny… hardly worth mentioning…micro little thing…

you didn’t set your rotation :stuck_out_tongue:

If this is the one you wanted to set/test/whatever?

 Quaternion rotation = Quaternion.Euler (new Vector3 (30, 0, 0));

:slight_smile:

 transform.rotation = Quaternion.Euler (new Vector3 (30, 0, 0));

haha, cheers. So, how would i get my player to sprint for say 3 seconds? I’m trying to figure it out with the mouse left click but failing to understand how that woud work with the current speed.

and tested but still doesn’t rotate XD. would i need to use the degreesPerSecond somewhere?

Not sure what sprinting for 3 seconds has to do with the original question :slight_smile:
Also, when you say it didn’t work… it didn’t rotate at all? or it didn’t rotate how you wanted it to rotate?

If it didn’t rotate at all, that’s weird.

it didn’t rotate at all and nah just curious :P. And this is the problem i’m facing, the way i did it before it rotated but not the way i wanted to as it looked outta place due to it being a sprite XD

this is 2d? you want to rotate the z-axis?
When you say it didn’t rotate at all, did it not even change in the inspector?

it is 2D and yeah the Z axis but yeah, it didn’t rotate in the inspector either… must be something im doing :confused:

I’m sorry, man, I’m confused.

well, if it helps i need it to rotate to where my mouse is pointing so similar t how the player moves towards the mouse

Right… but um… like it didn’t rotate lol

yeah, see let me pull out the other code.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;

public class Cell : Photon.MonoBehaviour {

    public Camera ourCamera ;

    public float Speed ;

    private Vector3 Target ;

    public float degreesPerSecond;


    void Awake()
    {
        photonView.RPC ("ChangeMyName", PhotonTargets.AllBuffered, PhotonNetwork.playerList.Length.ToString ());
    }

    [PunRPC]

    void ChangeMyName(string myNewName)
    {
        gameObject.transform.name = myNewName;
    }

    void Start ()
    {

        // if ourCamera is null then set the Main Camera to the variable ourCamera
        if (photonView.isMine)
        {
            ourCamera = Camera.main ;
        }


    }

    void Update ()
    {
        if (photonView.isMine)
        {//        DrawRay ();
            Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);

            Target.z = transform.position.z;
            Vector3 direction = Target - transform.position;
            if(!Mathf.Approximately(direction.sqrMagnitude,0))
            {
                Quaternion look = Quaternion.LookRotation(direction);
                transform.rotation = Quaternion.RotateTowards(transform.rotation,look,degreesPerSecond * Time.deltaTime);
            }
            transform.position = Vector3.MoveTowards (transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
        }
    }






}

this rotates it but makes it look like it’s 2.5D and spins it in the wrong way XD

Unfortunately, I’m not great with rotations. How to get it going gradually, I can’t figure that out atm…
I’d like to get more comfortable with using those myself…
In any event, there is this … better than nothing for now, maybe :slight_smile:

void Update()
    {
        if (!Input.GetMouseButton(0)) return;
        Vector3 mp = Input.mousePosition;
        mp.z = 15; // Camera was -15.

        Vector3 Target = Camera.main.ScreenToWorldPoint(mp);


        Vector3 direction = Target - transform.position;
        if (!Mathf.Approximately(direction.sqrMagnitude, 0))
        {

            float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

            transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
        }
        transform.position = Vector3.MoveTowards(transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
    }

okay, it works XD however, the player cannot pick up the gems XD need a vid?

no idea what you’re talking about… moving from 1 thing to another lol

right since i changed the code the camera now zeros out pushing the character behind the gems so basically it rotates but now it’s caused another problem XD

I don’t quite understand. Maybe someone can help…

How can you be behind gems in 2d? :S

that’s what i thought :confused: see when i had the camera in the child of the game object both kept spinning but i guess i should code the camera separate?

void Update ()
{
if (photonView.isMine)
{// DrawRay ();
Vector3 Target = Camera.main.ScreenToWorldPoint (Input.mousePosition);

Target.z = transform.position.z;
Vector3 direction = Target - transform.position;
if (!Mathf.Approximately(direction.sqrMagnitude, 0))
{

float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
transform.position = Vector3.MoveTowards (transform.position, Target, Speed * Time.deltaTime / transform.localScale.x);
}
}