Search Unity

How to make Hinge Joint object kind of rotate left and right

Discussion in 'Scripting' started by mykyta-pasternatskyi, Sep 11, 2019.

  1. mykyta-pasternatskyi

    mykyta-pasternatskyi

    Joined:
    Feb 23, 2019
    Posts:
    16
    Hi! I am trying to make a rope swinging system, right now it works pretty good with child cube and cyllinder with hinge joint, but I have problem with that when I am pressing the horizontal movement (I made a simple script, here:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class AddForceSwing : MonoBehaviour {
    6.     public Rigidbody RopeBottom;
    7.     // Use this for initialization
    8.     void Start () {
    9.      
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.         float horizontal = Input.GetAxis("Horizontal");
    15.         float vertical = Input.GetAxis("Vertical");
    16.  
    17.         RopeBottom.AddForce(transform.forward * vertical, ForceMode.Acceleration);
    18.         RopeBottom.AddForce(transform.right * horizontal , ForceMode.Acceleration);
    19.     }
    20. }
    21.  
    ) It is attached to a child cube which is adding the force to the bottom cyllinder (I made it using tutorial:
    , but I use only one cyllinder) And the issue is that the object doesnt rotate to the left or right. How can I do that? I made a short drawing of what the movement I'd like to do:

    Screenshot_12.png