Unity Vector3.Lerp

本文介绍了在Unity游戏开发环境中实现物体移动的两种方法:匀速运动和弹簧运动。通过设置移动时间和速率参数,可以控制物体从一个位置平滑地移动到另一个位置。这两种方法都使用了Vector3.Lerp函数来实现平滑过渡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、匀速运动

    public Transform from;
    public Transform to;
    public float mMoveTime = 1f;

    private float t = 0f;
    void Update()
    {
        t += 1f / mMoveTime * Time.deltaTime;
        from.position = Vector3.Lerp(from.position, to.position, t);
    }

二、弹簧运动

    public Transform from;
    public Transform to;
    public float mLerpRate = 15f;

    private float t;
    void Update()
    {
        t = mLerpRate * Time.deltaTime;
        from.position = Vector3.Lerp(from.position, to.position, t);
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值