Hello!
I created a fairly simple script to add motor.force/velocity to a gameobject.
But, I want it to increase it over time and not instant.
But i’m not sure on how to achieve this.
Still fairly new to C#.
If anyone can help me with this, that will be highly appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ArmMotor : MonoBehaviour
{
private HingeJoint _hingeJoint;
// Start is called before the first frame update
void Start()
{
_hingeJoint = GetComponent<HingeJoint>();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("e"))
{
JointMotor motor = _hingeJoint.motor;
motor.force = 0;
motor.targetVelocity = 0;
_hingeJoint.motor = motor;
}
if (Input.GetKeyDown("d"))
{
JointMotor motor = _hingeJoint.motor;
motor.force = 1500;
motor.targetVelocity = 90000;
_hingeJoint.motor = motor;
}
}
}