- Home /
Slowly increase joint limit over time
Hi there,
I'm working once again on a funfair game, but I'm not so much a scripter as I am a model builder.
I have created a super simple script which sets the joint limit to -90 and 0. But I want it to increase/decrease over a X amount of time, but i'm not sure on how to achieve said effect.
Is there anyone that can create a example for me that would work in my case?
That would be highly appereciated!
The is :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class limit : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
HingeJoint hinge = GetComponent<HingeJoint>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("e"))
{
HingeJoint hinge = GetComponent<HingeJoint>();
JointLimits limits = hinge.limits;
limits.min = 0;
limits.bounciness = 0;
limits.bounceMinVelocity = 0;
limits.max = -90;
hinge.limits = limits;
hinge.useLimits = true;
}
if (Input.GetKeyDown("d"))
{
HingeJoint hinge = GetComponent<HingeJoint>();
JointLimits limits = hinge.limits;
limits.min = 0;
limits.bounciness = 0;
limits.bounceMinVelocity = 0;
limits.max = 0;
hinge.limits = limits;
hinge.useLimits = true;
}
}
}
Answer by Zymurer · Feb 13, 2021 at 09:39 PM
You need to use Time.time method. It is basically a method used to see time since the play mode activated. You may create a variable and increase joint limit when Time.time - [your variable] reaches to a certain amount and set your variable to Time.time again.
For an example when your variable is zero and time past is 3 your hinge limit increases a certain amount and your vairable sets to three again.
I can send a code if you want further help.
If you would be so kind that would be so amazing!