2D Procedural Animation小试:尾巴,翅膀,触手等等

本文介绍了在2D游戏中使用Procedural Animation技术制作尾巴、翅膀和触手等身体部位动画的方法。通过控制rig和LineRenderer组件,结合数学函数实现动态摆动效果。文章探讨了Unity引擎中的Animation Rigging和UE4的Control Rig,并提供了一系列参考资料和示例代码。

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

Procedural Animation的百科解释:https://en.wikipedia.org/wiki/Procedural_animation

想深入了解UE4引擎中的: control rig, Unity引擎中的:Animation Rigging

最近在学习Procedural Animation相关的只是,先从2D开始。

最好理解的程序化动画就是贪吃蛇的运动,在此基础上改造添加身体部分的运动。  

 

 

Image 12.png

先简单代码,转向目标(鼠标位置)并向目标移动

image.png

 

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

[RequireComponent(typeof(Rigidbody))]
public class Controller : MonoBehaviour
{
    public float _speed = 1f;

    private Rigidbody _rigidbody;

    // Start is called before the first frame update
    void Start()
    {
        _rigidbody = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float multiplier = 1f;
        if (Input.GetKey(KeyCode.LeftShift))
        {
            multiplier = 2f;
            GetComponentInChildren<ProceduralAnimation>().running = true;
        }
        else
            GetComponentInChildren<ProceduralAnimation>().running = false;

        if (_rigidbody.velocity.magnitude < _speed * multiplier)
        {

            float value = Input.GetAxis("Vertical");
            if (value != 0)
                _rigidbody.AddForce(0, 0, value * Time.fixedDeltaTime * 1000f);
            value = Input.GetAxis("Horizontal");
            if (value != 0)
                _rigidbody.AddForce(value * Time.fixedDeltaTime * 1000f, 0f, 0f);
        }
    }
}

 

 

 

test222.gif

 

 

然后添加触角逻辑:

创建空对象Tentacle,添加LineRenderer 组件并进行设置:

image.png

 

创建脚本Tentacle.cs 并添加到对象上。

 

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

public class Tentacle : MonoBehaviour
{
    public int Length;
    public LineRenderer LineRend;
    public Vector3[] SegmentPoses;
    public Transform TargetDir;    // 是头部位置
    public float TargetDist;

    private Vector3[] SegmentV;
    public float SmoothSpeed;
    public float TrailSpeed;

    // Start is called before the first frame update
    void Start()
    {
        LineRend.positionCount = Length;
        SegmentPoses = new Vector3[Length];
        SegmentV = new Vector3[Length];
    }

    // Update is called once per frame
    void Update()
    {
        SegmentPoses[0] = TargetDir.position;
        for (int i = 1; i < SegmentPoses.Length; i++)
        {
            SegmentPoses[i] = Vector3.SmoothDamp(SegmentPoses[i], SegmentPoses[i - 1] + TargetDir.right * TargetDist, ref SegmentV[i], SmoothSpeed + i / TrailSpeed);
        }
        LineRend.SetPositions(SegmentPoses);
    }
}

 

 

需要自己去了解LineRenderer组件的用法。

image.png

image.png

 

image.png

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值