当前位置:网站首页>[100 unity practical skills] | make the skills or equipment follow the character and rotate continuously in the game

[100 unity practical skills] | make the skills or equipment follow the character and rotate continuously in the game

2022-06-21 12:18:00 Hua Weiyun

 Insert picture description here

  • This paper is written by A little fool Typing Code Y original

  • The learning column recommends :Unity Systematic learning column

  • Recommended in the game production column : Game making

  • Unity actual combat 100 Example column recommendation :Unity actual combat 100 example course

  • Welcome to thumb up Collection Leaving a message. Please correct any mistakes !

  • The future is long , It's worth our effort to go to a better life

  • ------------------️ Split line ️-------------------------

Unity Little science popularization

Old rules , Let me introduce you Unity A little knowledge of popular science :

  • Unity yes real time 3D Interactive content creation and operation platform .
  • Include Game development The fine arts Architecture Automobile design Movies All creators including , With the help of Unity Turn ideas into reality .
  • Unity The platform provides a complete set of software solutions , Can be used to create 、 Operate and realize any real-time interactive 2D and 3D Content , Support platforms include mobile phone The tablet PC Game consoles Augmented reality and Virtual reality device .
  • You can also simply put Unity Understood as a The game engine , It can be used for professional production game

Unity Step on the pit to learn a little knowledge

Unity Make one object rotate with another object all the time ( Rotation following )

Ideas : At the beginning of the game, get the vector of the position gap with the player , Then update the position of the following object , Then change the position to the specified distance , Finally, get the gap vector .

because RotateAround You can only rotate around the target , You cannot control the radius of rotation , So you need to constantly update the position to control the radius of rotation .

The effect is as follows :
 Please add a picture description

The code to follow the rotation is as follows :

using System.Collections;using System.Collections.Generic;using UnityEngine; public class Saber : MonoBehaviour {    public Transform targetPos;// Rotate center object     public float speed = 200f;// Rotation speed     public float distance;// Radius of rotation     Vector3 dir;        void Start()     {        dir = transform.position - Target.transform.position;    }     void Update() {        // Update the position of the following object         transform.position = targetPos.position + dir.normalized * distance;        // Rotate around the character         transform.RotateAround(targetPos.position, Vector3.up, speed * Time.deltaTime);        // Update direction vector         dir = transform.position - targetPos.position;    } 

 Insert picture description here

原网站

版权声明
本文为[Hua Weiyun]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/172/202206211059224120.html