Question by
Jass777 · Jun 26, 2016 at 11:07 AM ·
springhinge jointhinge
hinge joint and spring not reacting to input
so the problem is, i added a spring to a object to make it act like a catapult and its scripted to turn with a input key, But its not working, the input is recognized, checked with debug.log, but the object not moving. also im new to unity, :)
using UnityEngine;
using System.Collections;
public class Leftpaddle : MonoBehaviour {
public float pressed ;
public float unpressed ;
public string leftpad;
// Use this for initialization
void Start() {
HingeJoint hinge = GetComponent<HingeJoint>();
JointSpring spring = hinge.spring;
spring.spring = 1000;
spring.damper = 10;
hinge.useSpring = true;
}
void Update ()
{
HingeJoint hinge = GetComponent<HingeJoint> ();
JointSpring springs = hinge.spring;
hinge.useSpring = true;
springs.spring = 1000;
springs.damper = 10;
if (Input.GetButton (leftpad)) {
springs.targetPosition = pressed;
Debug.Log (springs.targetPosition );
}
else {
springs.targetPosition = unpressed;
Debug.Log (springs.targetPosition );
}
}
}
code.png
(61.0 kB)
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612083711im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How do you get the hinge joint working on all Axis? 3 Answers
Hinge Joint Doesn't Move Unity 2018.4.17f1 0 Answers
need help with a sway and recoil script for a weapon. 0 Answers
How does hinge joint work? 0 Answers