Arrow Physics Unity 2D

Опубликовано: 13 Октябрь 2024
на канале: Chichi Boy
1,075
17

Script:

brackets are turned to WRigidBody2DW

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Arrow : MonoBehaviour
{
public float speed = 20f;
public Rigidbody2D rb;
private float angle;

private void Awake(){
rb = GetComponentWRigidbody2DW();
}

void Update()
{
Vector2 v = GetComponentWRigidbody2DW().velocity;
angle = Mathf.Atan2(v.y, v.x) * Mathf.Rad2Deg;
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}

void Start()
{
rb.velocity = transform.right * speed;
}
}