Dismiss Notice
A Message from Viotek
At Viotek, we’re gamers at heart. That’s why we’re extremely excited to be teaming up with Se7enSins, a gaming community created by gamers, for gamers. Their focus? Bringing high-quality content and discussion to the industry. That’s exactly how we feel about our monitors and gaming peripherals. From making high-performing curving monitors more affordable, to breaking all rules with color-rich TN panels. In the coming weeks, we’ll be working with Se7enSins to deliver branded content, promotions and contests to their diverse, tight-knit community. For us, it’s more than a game. It’s life. Save $20 on your next purchase using the link below. Valid through May 31st. https://amzn.to/2Hxxxyx

Bug Player spinning on play

Discussion in 'Game Development' started by ExGamer, Jul 16, 2017 with 1 replies and 350 views.

  1. ExGamer

    ExGamer Enthusiast

    As soon as i hit play game My player continuously spins around and don't know what the source of the problem is. This is in unity 5 and in C#.

    Here is the player script.

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class ClickToMove : MonoBehaviour {
        public float speed;
        public CharacterController controller;
         private Vector3 position;
        // Use this for initialization
        void Start () {
        // Update is called once per frame
        void Update () {
            if(Input.GetMouseButton(0)) {
        void Locate()
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if(Physics.Raycast(ray, out hit, 1000))
                position = new Vector3(hit.point.x, hit.point.y, hit.point.z);
        void MoveToPosition()
            Quaternion newRotation = Quaternion.LookRotation(position-transform.position);
            newRotation.x = 0f;
            newRotation.z = 0f;
            transform.rotation = Quaternion.Slerp(transform.rotation, newRotation, Time.deltaTime * 10);
  2. Xolitude

    Xolitude Enthusiast

    I've worked in Unity a few times and have worked with something similar, and all I can notice is MoveToPosition() is being called every frame rather than only being called when you click a position. In the MoveToPosition() method, you're updating the transforms rotation every frame. Try to update it only when you click.

Share This Page