Version: 2020.2
LanguageEnglish
  • C#

HingeJoint.spring

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public JointSpring spring;

Description

The spring attempts to reach a target angle by adding spring and damping forces.

The JointSpring.spring force attempts to reach the target angle. A larger value makes the spring reach the target position faster.

The JointSpring.damper force dampens the angular velocity. A larger value makes the spring reach the goal slower.

The spring reaches for the JointSpring.targetPosition angle in degrees relative to the rest angle. The rest angle between the bodies is always zero at the beginning of the simulation.

See Also: useSpring, JointSpring.

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; } }

Modifying the spring does not automatically enable it.

Enabling the motor overrides the spring, given the spring was enabled. If the motor is again disabled the spring will be restored.

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961