划线组件LineRenderer+刚体力的模式

划线组件相关属性

Material:划线的材质;

Positions:多个点,划线的点集;

Use World Space:是否使用世界坐标系;

Loop:是否循环,是指第一个点和最后一个点是否形成闭环;

Width:划线的宽度,通过曲线来控制;

LineRenderer组件应用小案例:

使用LineRenderer相关属性画出一个三角形

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

public class LineRendererTest : MonoBehaviour
{
    private LineRenderer line;
    // Start is called before the first frame update
    void Start()
    {
        line = gameObject.GetComponent<LineRenderer>();
        line.positionCount = 3;
        line.SetPosition(0, new Vector3(0, 0, 0));
        line.SetPosition(1, new Vector3(0,0,10));
        line.SetPosition(2, new Vector3(10,0,0));
        line.loop = true;
    }
}

将以上脚本挂载到有LineRenderer组件的游戏物体上,运行游戏,实现结果如图所示:

实现当运行游戏时,用鼠标充当画笔,实现绘图功能:

对应代码如下所示:

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

public class LineRendererTest : MonoBehaviour
{
    private LineRenderer line;
    private int pointCount;
    private Vector3 position;
    void Start()
    {
        line = gameObject.GetComponent<LineRenderer>();
    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            pointCount++;
            position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 5));
            Debug.Log("position:" + position);
            line.positionCount = pointCount;
            line.SetPosition(pointCount - 1, position);
        }
    }
}

运行游戏,实现效果如图:

力   AddForce

力是矢量,有大小有方向 ;

牛顿第二定律:F=ma      动量守恒定律: M1V1=M2V2        动量定理:Ft=mv=Impulse冲量

1.AddForce:

cube0.AddForce(new Vector3(0,0,100),ForceMode.Acceleration);
cubel.AddForce(new Vector3(0,0,100),ForceMode.Force);

ForceMode.Acceleration:关注的是加速度,所以跟物体的质量不相关 ;

ForceMode.Force:关注的是力的整体,也就是m*a的值,这时跟物体的质量相关

Ft=mv

ForceMode.Impulse:关注的是冲量的整体,也就是m*v的值,这时跟物体的质量相关;

ForceMode.VelocityChange:关注的是速度,所以和物体的质量不相关;

2.扭矩,让一个cube旋转

cube0.AddTorque(Vector3.forward*50,ForceMode.Impulse);

该系列专栏为网课课程笔记,仅用于学习参考。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值