Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Set position of a surface to a point

Discussion in 'Scripting' started by bora155, Apr 19, 2021.

  1. bora155

    bora155

    Joined:
    Mar 31, 2020
    Posts:
    12
    Hello there , what i want is kinda complicated to tell in text so im just going to explain it with some pictures

    I already have implemented to change the rotation . I need to know how to implement moving the position

    1.PNG 2.PNG 3.png 4.PNG

    Would be really glad for some help :D
     
  2. bora155

    bora155

    Joined:
    Mar 31, 2020
    Posts:
    12
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class WorldRevolve : MonoBehaviour
    6. {
    7.     [Tooltip("Basically smoothness but opposite")]
    8.     public float roughness = 1f;
    9.     [Tooltip("Cooldown . Preferably set this to roughness")]
    10.     public float cooldown = 1f;
    11.  
    12.     PlayerMovement playerController;
    13.  
    14.     private Quaternion targetRotation;
    15.     private Vector3 targetPosition;
    16.  
    17.     private float turnRate = 0f;
    18.  
    19.     GameObject world;
    20.     GameObject player;
    21.  
    22.     // Start is called before the first frame update
    23.     void Start()
    24.     {
    25.         targetRotation = transform.rotation;
    26.  
    27.         world = GameObject.FindGameObjectWithTag("World");
    28.         player = GameObject.FindGameObjectWithTag("Player");
    29.  
    30.         playerController = player.GetComponent<PlayerMovement>();
    31.     }
    32.  
    33.     private void Update()
    34.     {
    35.         if (Input.GetKeyDown(KeyCode.E) && Time.time >= turnRate)
    36.         {
    37.             turnRate = Time.time + cooldown;
    38.             targetRotation *= Quaternion.AngleAxis(90, Vector3.up);
    39.         }
    40.         if (Input.GetKeyDown(KeyCode.Q) && Time.time >= turnRate)
    41.         {
    42.             turnRate = Time.time + cooldown;
    43.             targetRotation *= Quaternion.AngleAxis(-90, Vector3.up);
    44.         }
    45.  
    46.         transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, Time.deltaTime * roughness);
    47.  
    48.         if (Time.time >= turnRate)
    49.         {
    50.             playerController.frozen = false;
    51.         }
    52.         if (Time.time < turnRate)
    53.         {
    54.             playerController.frozen = true;
    55.         }
    56.     }
    57.    
    58. }
    59.