作业三

简答题

游戏对象运动的本质

游戏对象运动的本质,就是游戏对象跟随每一帧发生变化的过程。在变化的过程中,主要是指游戏对象的transform中的rotation与position两个属性。其中,rotation是指游戏对象所处位置的角度变化,而position则是指游戏对象在坐标系中位置的改变。

请用三种方法以上方法,实现物体的抛物线运动

要实现物体的抛物线运动,我们需要将物体在水平方向和垂直方向上分别进行位移,两者叠加之后即可实现抛物运动。在水平方向上我们让其速度保持不变,在竖直方向上让其速度逐渐增加。
我们都定义水平方向的速度为vx而竖直方向上的速度的vy
第一种方法,直接利用物体position的改变来进行操作:

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

public class paraCurve1 : MonoBehaviour {
   

    public float vx = 1;
    public float vy = 0;
    // Use this for initialization
    void Start () {
   
		
	}
	
	// Update is called once per frame
	void Update () {
   
        vy += 0.5f;
        this.transform.position += Vector3.right * Time.deltaTime * vx;
        this.transform.position += Vector3.down * Time.deltaTime * vy;
    }
}

第二种方法,我们将物体的改变用一个新的Vector3向量来表示,将其和物体原本向量叠加:

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

public class paraCurve2 : MonoBehaviour {
   

    public float vx = 1;
    public float vy = 0;
	// Use this for initialization
	void Start () {
   
		
	}
	
	// Update is called once per frame
	void Update () {
   
        vy += 0.5f;
        Vector3 change = new Vector3(Time.deltaTime * vx, - Time.deltaTime * vy, 0);
        this.transform.position += change;
	}
}

第三种方法,我们调用transform中的translate函数来改变position,同样也会利用到Vector3向量:

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

public class paraCurve3 : MonoBehaviour {
   

    public float vx = 1;
    public float vy = 0;
    // Use this for initialization
    void Start () {
   
		
	}
	
	// Update is called once per frame
	void Update () {
   
        vy += 0.5f;
        Vector3 change = new Vector3(Time.deltaTime * vx, -Time.deltaTime * vy, 0);
        this.transform.Translate(change);
    }
}

实现一个完整的太阳系

我们首先按照太阳系行星和它们所处的位置、大小建立一个对象树:
在这里插入图片描述
然后为它们添加一些简单的贴图,按照位置排列在太阳的周围:
在这里插入图片描述
为了实现行星绕太阳旋转,我们需要利用到RotationAround函数来进行实现,其包括参数:旋转中心、旋转轴和旋转速度。为了简便整个代码,我们将所有旋转写在一个C
#文件里面,利用GameObject.Find函数找到每个对象。在围绕太阳旋转的同时,我们还利用Rotation函数给每个行星添加了自转,为了简便我们令所有行星的自转速度相同。

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

public class SolarSystem : MonoBehaviour {
   

	// Use this for initialization
	void Start () {
   
		
	}
	
	// Update is called once per frame
	void Update () {
   
        GameObject.Find("Mercury").transform.RotateAround(Vector3.zero, new Vector3(1, 1, 0), 25 * Time.deltaTime);
        GameObject
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值