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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

how i increment a variable

Discussion in 'Scripting' started by Trild123787898, Nov 7, 2021.

  1. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    how can I smoothly increase the Hingle Joint TargetPosition parameter, let's say from 0 to 50, there is no further, I tried to use MoreTowards, but I could not, I will be glad to help
     
  2. davidnibi

    davidnibi

    Joined:
    Dec 19, 2012
    Posts:
    424
    Can you post up your code, will give everyone a better chance at helping you.

    If the target position is just a value, I wouldn't use movetowards to pass it onto the hinge joint.
     
  3. Trild123787898

    Trild123787898

    Joined:
    Dec 9, 2018
    Posts:
    206
    so, I need to get the value 7 at a certain speed
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Mehanics : MonoBehaviour
    6. {
    7.     public HingeJoint joint_1;
    8.     public GameObject gm_1;
    9.      JointSpring springjoint;
    10.  
    11.  
    12. void Start()
    13. {
    14.     joint_1 = gm_1.GetComponent<HingeJoint>();
    15.     springjoint = joint_1.spring;
    16. }
    17.     void FixedUpdate()
    18.     {
    19.         if(Input.GetKey(KeyCode.T))
    20.         {
    21.             springjoint.targetPosition = 7;
    22.             joint_1.spring = springjoint;
    23.         }
    24.     }
    25. }