3D游戏编程作业3

作业内容

    实现物体的抛物线运动。

作业实现

    此次作业需要制作出平板和小球,让小球在平板上做抛物线运动,平板和小球的制作较为简单。主要分析运动代码。

    

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

public class sport : MonoBehaviour
{
    public float v0 = 98;//初速度
    public float y0 = 0;//初始y坐标
    public float x0 = 0;//初始x坐标
    public float vx = 0;//x轴的速度
    public float vy = 0;//y轴的速度
    public float angle = 45;//初速度和x轴的夹角
    public float t = 0;//运动的总时长
    public float x = 0;//x坐标
    public float y = 0;//y坐标
    public float temp = 0;//小球运动一个周期时间

    // Start is called before the first frame update
    void Start()
    {
        vx = v0 * Mathf.Cos(angle * Mathf.Deg2Rad);
        vy = v0 * Mathf.Cos(angle * Mathf.Deg2Rad);
        temp = 2 * vy / 9.8f;
    }

    // Update is called once per frame
    void Update()
    {
        t = t + Time.deltaTime;
        x = vx * t;
        float T = t % temp;
        y = vy * T - 0.5f * 9.8f * Mathf.Pow(T, 2);//使小球不断地往前滚动
        Vector3 p = new Vector3(x, y, 0);
        if (y >= 0)
        {
            transform.position = p;
        }
    }
}

在此次作业中,我让小球可以不断的往前运动,无视小球的物理碰撞,只是简单的向前运动。

场景展示:

视频演示:

抛物线运动

源码:作业3 · BaiLee/3D游戏编程 - 码云 - 开源中国 (gitee.com)

只包含Assets。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值