Answers for "unity dynamically set hinge joint spring target position"

C#
0

unity dynamically set hinge joint spring target position

using UnityEngine;
using System.Collections;


public class HingeExample : MonoBehaviour
{
    void Start()
    {
        HingeJoint hinge = GetComponent<HingeJoint>();

        // Make the spring reach shoot for a 70 degree angle.
        // This could be used to fire off a catapult.

        JointSpring hingeSpring = hinge.spring;
        hingeSpring.spring = 10;
        hingeSpring.damper = 3;
        hingeSpring.targetPosition = 70;
        hinge.spring = hingeSpring;
        hinge.useSpring = true;
    }
}
Posted by: Guest on August-02-2020

C# Answers by Framework

Browse Popular Code Answers by Language