3D游戏编程 作业三 简答题

实验题传送门:实验题

简答并用程序验证

1. 游戏对象运动的本质是什么?

游戏对象跟随每一帧的变化,空间地变化。这里的空间变化包括了游戏对象的transform属性中的position跟rotation两个属性。一个是绝对或者相对位置的改变,一个是所处位置的角度的旋转变化。

2.请用三种方法以上方法,实现物体的抛物线运动。(如,修改Transform属性,使用向量Vector3的方法…)

1)直接改变Transform属性

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

public class move : MonoBehaviour
{
    // Start is called before the first frame update
    public float speed = -1;
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        this.transform.position += Vector3.down*Time.deltaTime*(speed/10);
        this.transform.position += Vector3.left*Time.deltaTime*5;
        speed++;
    }
}

2)使用Vector3

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

public class move : MonoBehaviour
{
    // Start is called before the first frame update
    public float speed = -1;
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Vector3 go = new Vector3(Time.deltaTime*5,-Time.deltaTime*(speed/10),0);
        this.transform.position += go;
        speed++;
    }
}

3)调用其他组件的Transform属性

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

public class move : MonoBehaviour
{
    // Start is called before the first frame update
    public float speed = -1;
    public Transform obj;
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        obj.position += Vector3.down*Time.deltaTime*(speed/10);
        obj.position += Vector3.left*Time.deltaTime*5;
        speed++;
    }
}

3.写一个程序,实现一个完整的太阳系, 其他星球围绕太阳的转速必须不一样,且不在一个法平面上

贴图效果

运行脚本

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

public class move : MonoBehaviour
{
    // Start is called before the first frame update
    public Transform Sun;
    public Transform Mercury;
    public Transform Venus;
    public Transform Earth;
    public Transform Mars;
    public Transform Jupiter;
    public Transform Saturn;
    public Transform Uranus;
    public Transform Neptune;
    
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        Sun.Rotate(Vector3.up * Time.deltaTime * 10000);
        Earth.RotateAround(Vector3.zero, new Vector3(0, 1, 0), 30 * Time.deltaTime);//公转
        Earth.Rotate(Vector3.up * Time.deltaTime * 10000);//自转
        Mercury.RotateAround(Vector3.zero, new Vector3(1, 1, 0), 25 * Time.deltaTime);
        Mercury.Rotate(Vector3.up * Time.deltaTime * 10000);
        Venus.RotateAround(Vector3.zero, new Vector3(0, 1, 1), 20 * Time.deltaTime);
        Venus.Rotate(Vector3.up * Time.deltaTime * 10000);
        Mars.RotateAround(Vector3.zero, new Vector3(2, 1, 0), 45 * Time.deltaTime);
        Mars.Rotate(Vector3.up * Time.deltaTime * 10000);
        Jupiter.RotateAround(Vector3.zero, new Vector3(1, 2, 0), 35 * Time.deltaTime);
        Jupiter.Rotate(Vector3.up * Time.deltaTime * 10000);
        Saturn.RotateAround(Vector3.zero, new Vector3(0, 1, 2), 40 * Time.deltaTime);
        Saturn.Rotate(Vector3.up * Time.deltaTime * 10000);
        Uranus.RotateAround(Vector3.zero, new Vector3(0, 2, 1), 45 * Time.deltaTime);
        Uranus.Rotate(Vector3.up * Time.deltaTime * 10000);
        Neptune.RotateAround(Vector3.zero, new Vector3(1, 1, 1), 50 * Time.deltaTime);
        Neptune.Rotate(Vector3.up * Time.deltaTime * 10000);

    }
}

运行此脚本时需要注意配置脚本的坐标系

 

运行效果

最终游戏对象如图,地月间的相互运动不再具体实现

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值