unity 关于射箭时候抛物线,计算

记录一下,
 

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

public class BulletTest : MonoBehaviour
{
    private Vector2 target_pos;
    private Rigidbody2D _rigidbody;
    private float x_Speed=10;
    private float mass = -9.8f;
    private float y_speed;
    private float moveTime;

    private Vector3 MoveSpeed;
    private Vector3 MasSpeed = Vector2.zero;

    private bool ismove = false;
    public void Init(Transform monster)
    {
        target_pos = monster.position;
        float x = target_pos.x - transform.position.x;
        float y = -transform.position.y + target_pos.y;
        //计算箭只移动到目的地的时间
        moveTime = x / x_Speed;
        //计算y轴上的初始速度
        y_speed = y / moveTime - 0.5f*mass * moveTime;

        //初始速度向量
        MoveSpeed = new Vector3(x_Speed, y_speed);

        //旋转角度
        float eul = Mathf.Atan(y_speed / x_Speed) * 180 / Mathf.PI;
        this.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值