Search Unity

Problem with moving the platform.

Discussion in 'Getting Started' started by Deleted User, Oct 20, 2018.

  1. Deleted User

    Deleted User

    Guest

    Hey. I have a problem with the script responsible for moving the platform. When a player enters the platform, he changes his shape. What should the ball do not change its shape?

    Film:


    My script:
    PlayerMove:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerMove : MonoBehaviour {
    6.  
    7.     void Update()
    8.     {
    9.         Rigidbody rigidbody = transform.GetComponent<Rigidbody>();
    10.         float velocity = 2f;
    11.  
    12.         if ((Input.GetKey(KeyCode.UpArrow)) || (Input.GetKey(KeyCode.W)))
    13.         {
    14.             rigidbody.AddTorque(-Vector3.forward * velocity);
    15.         }
    16.  
    17.         if ((Input.GetKey(KeyCode.DownArrow)) || (Input.GetKey(KeyCode.S)))
    18.         {
    19.             rigidbody.AddTorque(Vector3.forward * velocity);
    20.         }
    21.  
    22.         if ((Input.GetKey(KeyCode.LeftArrow)) || (Input.GetKey(KeyCode.A)))
    23.         {
    24.             rigidbody.AddTorque(-Vector3.left * velocity);
    25.         }
    26.  
    27.         if ((Input.GetKey(KeyCode.RightArrow)) || (Input.GetKey(KeyCode.D)))
    28.         {
    29.             rigidbody.AddTorque(Vector3.left * velocity);
    30.         }
    31.     }
    32. }
    33.  
    PlatformLeftRight

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlatformLeftRight : MonoBehaviour {
    6.  
    7.     public GameObject player;
    8.  
    9.     private void OnTriggerEnter(Collider other)
    10.     {
    11.         if (other.gameObject == player)
    12.         {
    13.             player.transform.parent = transform;
    14.         }
    15.     }
    16.     private void OnTriggerExit(Collider other)
    17.     {
    18.         if (other.gameObject == player)
    19.         {
    20.             player.transform.parent = null;
    21.         }
    22.     }
    23. }
    24.  
     
  2. Green11001

    Green11001

    Joined:
    Apr 14, 2018
    Posts:
    397
    Ummm i think the player is scaling to the platform.