@VovaGatova

Что делать если не роботает Hingle Joint 2d Unity?

Я сделал перемещение мышью чтобы было реалистично, Я добавил Hingle Joint 2d
И соеденил с мышью(Обьект )
У меня нечего не роботает помогите
Вот код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DragItems : MonoBehaviour
{
public Rigidbody2D selectedObject;
public HingeJoint2D StopCenter = null;
public Rigidbody2D obj;

public Vector2 Mouse;
public Transform Mousetransofrm;
Vector3 offset;
Vector3 mousePosition;
public float maxSpeed=10;
Vector2 mouseForce;
Vector3 lastPosition;
void Update()
{
Mouse = Mousetransofrm.transform.position;
mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
if (selectedObject)
{
mouseForce = (mousePosition - lastPosition) / Time.deltaTime;
mouseForce = Vector2.ClampMagnitude(mouseForce, maxSpeed);
lastPosition = mousePosition;
}
if (Input.GetMouseButtonDown(0))
{
Collider2D targetObject = Physics2D.OverlapPoint(mousePosition);
if (targetObject)
{
selectedObject = targetObject.transform.gameObject.GetComponent();
offset = selectedObject.transform.position - mousePosition;
}
}
if (Input.GetMouseButtonUp(0) && selectedObject)
{
selectedObject.velocity = Vector2.zero;
selectedObject.AddForce(mouseForce, ForceMode2D.Impulse);
selectedObject = null;
}
}
void FixedUpdate()
{
if (selectedObject)
{
selectedObject.MovePosition(mousePosition + offset);
StopCenter = selectedObject.GetComponent();
StopCenter.enabled = true;
StopCenter.connectedBody = obj;
StopCenter.anchor = Mouse;
}
}
}
  • Вопрос задан
  • 27 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы