- Home /
 
 
               Question by 
               verschurengiovanni · Aug 26, 2021 at 12:07 AM · 
                scripting problemmovementscript.  
              
 
              Moving a object up
Hello,
I'm currently working on a funfair simulation. The code I have is responsible for the up/down movement of the cylinders.
It works flawless when there are no connected hinges/rigidbodies, but once added it glitches out.
I think something in my code is wrong, but i'm not sure what is the problem. My guess is the "transform.position", but i'm not sure what to replace it with.
I hope someone can help me fix this :)
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class KoppieKoppie : MonoBehaviour
 {
     public KeyCode increaseKey;
     public KeyCode decreaseKey;
     public float maxHeight;
     public float changePerFrame = 1;
     public float progress { get; private set; }
     public Schuin schuin;
     public Text progressText;
     private float lastAnimation = 0;
 
     private float height = 0.0f;
     private float initialY;
     
 
     public float richting = -1.0f;
 
     void Start()
     {
       initialY = transform.position.y;
     }
 
     void Update()
     {
         if (Input.GetKey(increaseKey) && (lastAnimation == 0 || Time.time - lastAnimation > 3))
         {
             richting = 1.0f;
             lastAnimation = Time.time;
         }
         else if (Input.GetKey(decreaseKey) && (schuin.progress <= 0.005f) && (lastAnimation == 0 || Time.time - lastAnimation > 3))
         {
             richting = -1.0f;
             lastAnimation = Time.time;
 
         }
 
        progress = Mathf.Min(1, Mathf.Max(0, progress + (richting * changePerFrame * Time.maximumDeltaTime)));
        transform.position = new Vector3(transform.position.x, initialY + progress * maxHeight, transform.position.z);
 
         if (progressText != null)
             progressText.text = (progress * 100).ToString("0") + "%";
     }
 }
 
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Smooth jump script? 1 Answer
Question about moving an object technique 3 Answers
The Camera is facing backwards of the Character 1 Answer
How do I slow down while Im Sliding? 0 Answers