How Can I Set A Springjoint2D's Frequency In A Script?
Hey, I'm wondering how to set a Springjoint2D's frequency (and maybe the distance and dampening ratio as well) in a script. I've soured all over the internet and unity docs for this answer. Is it even possible?
Answer by HenryStrattonFW · Feb 04, 2017 at 05:07 PM
https://docs.unity3d.com/ScriptReference/SpringJoint2D.html
According to the docs yes. frequency, distance and dampingRatio are all public float variables on the component. so you just have to set them, as a crude example the code below just sets them all to 0.
using UnityEngine;
public class Test : MonoBehaviour
{
[SerializeField]
private SpringJoint2D m_Joint;
void Awake()
{
m_Joint.frequency = 0; //your desired frequency here.
m_Joint.distance = 0; //your desired distance here.
m_Joint.dampingRatio = 0; //your desired dampingRatio here.
}
}
Or are you already doing this and experiencing some issues with it not working?
Your answer
Follow this Question
Related Questions
What is the most effective way to structure Card Effects in a Single Player game? 1 Answer
Multiple Sprites, One Script, Randomization 1 Answer
Any one help me in this script? 0 Answers
How to render text on top of the objects that are generated on the map using a script? 1 Answer
Problems disabling an AI and giving control to the Player 0 Answers