当前位置:网站首页>unity实战之lol技能释放范围
unity实战之lol技能释放范围
2022-06-24 18:58:00 【华为云】
前言
最近英雄联盟手游开启不删档测试,对于忠实的lol玩家来说,又激起了我对手游的兴趣。赶紧趁着开服,果断删掉所有手游,清理一波内存,开启我的手游版lol体验。(没办法手机内存太小了)。果断跳过新手教程开始匹配赛,终于到达10级了,又赶紧体验了几把排位赛,虽然体验后觉得端游更胜一筹,但是就凭手游方便的特点,我依然把它保留在了手机了。
激烈的混战中,出现如下画面:
本队小姐姐一个接一个的送人头,这时候暴躁哥出现了,开始一顿狂bibi。
小姐姐也很无奈:她的手太长了,为什么我就打不到他~。
攻击范围定义
作为一个lol忠实粉丝and游戏开发者来,我必须来为大家分析一下攻击范围:顾名思义,攻击范围就是释放技能后,会对进入这个范围的敌方单位造成伤害一定英雄,包括伤害,眩晕等。
那么我方释放了一个技能,该技能存在一个攻击范围,如何判断敌方是否在该范围内受到影响?
矩形攻击范围

向正前方释放一个技能,当攻击范围为一个矩形(a,b)时,判断敌方是否受到伤害,需满足三个条件
(1)敌方位于我放方正前方
(2)敌方位于a长度内
(3)敌方位于b宽度内
游戏中场景转换成如下示意图:
翻译成数学语言:
(1)两向量点积>0
(2)在a上的投影<a
(3)在b上的投影<b
(1)点积判断
Vector3 forward = hero_a.forward;Vector3 direction = hero_b.position - hero_a.position;float dot = Vector3.Dot(forward,direction);if (dot >0){}(2)水平方向投影判断
float horizontal = Vector3.Project(direction, hero_a.right).magnitude;//水平方向投影if (horizontal <= length/2){}(3)垂直方向投影判断
float vertical = Vector3.Project(direction, hero_a.forward).magnitude;//垂直方向投影if (vertical <= width){}(4)绘制攻击范围
private void OnDrawGizmos() { Handles.color = isShow ? Color.cyan : Color.red; Vector3 cornerA = hero_a.position + Vector3.left * width * .5f; Vector3 cornerB = hero_a.position + Vector3.right * width * .5f; Vector3 cornerC = cornerB + Vector3.forward * length; Vector3 cornerD = cornerA + Vector3.forward * length; Handles.DrawLine(cornerA, cornerB); Handles.DrawLine(cornerB, cornerC); Handles.DrawLine(cornerC, cornerD); Handles.DrawLine(cornerD, cornerA); }
完整脚本:
using UnityEngine;using UnityEditor;public class SkillRang : MonoBehaviour{ public float length = 1f;//矩形长 public float width = 1f;//矩形宽 private bool isShow = false;//是否处于攻击范围 private Transform hero_a;//我方英雄 private Transform hero_b;//敌方英雄 // Start is called before the first frame update void Start() { hero_a = GameObject.Find("hero_a").transform; hero_b = GameObject.Find("hero_b").transform; } // Update is called once per frame void Update() { RectRang(); } private void RectRang() { //方形区域 Vector3 forward = hero_a.forward; Vector3 direction = hero_b.position - hero_a.position; float dot = Vector3.Dot(forward,direction); if (dot >0) { //在前方 float vertical = Vector3.Project(direction, hero_a.forward).magnitude;//垂直方向投影 float horizontal = Vector3.Project(direction, hero_a.right).magnitude;//水平方向投影 if (vertical <= width && horizontal <= length/2) { isShow = true; return; } } isShow = false; } private void OnDrawGizmos() { Handles.color = isShow ? Color.cyan : Color.red; Vector3 cornerA = hero_a.position + Vector3.left * length * .5f; Vector3 cornerB = hero_a.position + Vector3.right * length * .5f; Vector3 cornerC = cornerB + Vector3.forward * width; Vector3 cornerD = cornerA + Vector3.forward * width; Handles.DrawLine(cornerA, cornerB); Handles.DrawLine(cornerB, cornerC); Handles.DrawLine(cornerC, cornerD); Handles.DrawLine(cornerD, cornerA); }}圆形攻击范围

释放一个技能,当攻击范围为一个矩形(半径为r)时,判断敌方是否受到伤害,需满足一个条件:
(1)敌人处在一个圆内或者圆上。该圆是以释放技能处未圆心,r为半径的圆。
游戏中场景转换成如下示意图:
翻译成数学语言:
(1)
假设攻击范围半径为radius
(1)距离计算
Vector3 pos_a = hero_a.position;Vector3 pos_b = hero_b.position;float distence = Mathf.Sqrt((pos_a.x-pos_b.x)*(pos_a.x-pos_b.x)+(pos_a.y-pos_b.y)*(pos_a.y-pos_b.y));(2)距离判断
if (distence <= radius){}(3)绘制攻击范围
private void OnDrawGizmos(){ Handles.color = isShow ? Color.cyan : Color.red; Handles.CircleHandleCap(0,hero_a.position,hero_a.rotation * Quaternion.LookRotation(Vector3.up),radius,EventType.Repaint); }
完整脚本:
using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEditor;public class SkillRang : MonoBehaviour{ public float radius = 1f;//圆形半径 private bool isShow = false;//是否处于攻击范围 private Transform hero_a;//我方英雄 private Transform hero_b;//敌方英雄 // Start is called before the first frame update void Start() { hero_a = GameObject.Find("hero_a").transform; hero_b = GameObject.Find("hero_b").transform; } // Update is called once per frame void Update() { CricleRang(); } private void CricleRang() { // 圆形区域 Vector3 pos_a = hero_a.position; Vector3 pos_b = hero_b.position; float distence = Mathf.Sqrt((pos_a.x-pos_b.x)*(pos_a.x-pos_b.x)+(pos_a.y-pos_b.y)*(pos_a.y-pos_b.y)); if (distence <= radius) { isShow = true; } else { isShow = false; } } private void OnDrawGizmos() { Handles.color = isShow ? Color.cyan : Color.red; Handles.CircleHandleCap(0,hero_a.position,hero_a.rotation * Quaternion.LookRotation(Vector3.up),radius,EventType.Repaint); }}工程源码:https://gitee.com/shirln/skill-rang
注意:本文参考自https://blog.csdn.net/qq_42139931/article/details/120712908
边栏推荐
- Oracle create tablespaces and tables
- The cdc+mysql connector joins the date and time field from the dimension table by +8:00. Could you tell me which one is hosted by Alibaba cloud
- Database index can improve query efficiency. Ask what will improve, what is the difference between inapplicable index and index use, and what will happen.
- Dataworks development ODPs SQL development production environment automatic completion of ProjectName
- Write a positive integer to the node and return a floating-point number multiplied by 0.85 when reading the node
- First understand redis' data structure - string
- R for Data Science (notes) -- data transformation (used by filter)
- 60 divine vs Code plug-ins!!
- Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
- 【云驻共创】ModelBox隔空作画 绘制你的专属画作
猜你喜欢

An accident caused by a MySQL misoperation cannot be withstood by High Availability!

Experience of MDM master data project implementation for manufacturing projects

Volcano成Spark默认batch调度器

Understanding openstack network

Vs2017 add header file path method

60 个神级 VS Code 插件!!

Install the custom module into the system and use find in the independent project_ Package found

STM32 uses time delay to realize breathing lamp register version

应用实践 | 海量数据,秒级分析!Flink+Doris 构建实时数仓方案

What about the Golden Angel of thunder one? Golden Angel mission details
随机推荐
What is CNN (convolutional neural network)
three. Basic framework created by JS
Bytebase joins Alibaba cloud polardb open source database community
Capacitive inching touch switch module control (stm32f103c8t6)
【CANN文档速递04期】揭秘昇腾CANN算子开发
The agile way? Is agile development really out of date?
Bytebase 加入阿里云 PolarDB 开源数据库社区
Fundamentals of performance testing -- definitions of common terms
【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
Working for 6 years with a monthly salary of 3W and a history of striving for one PM
Camera module and hardware interface of Camera1 camera
Database index can improve query efficiency. Ask what will improve, what is the difference between inapplicable index and index use, and what will happen.
RF_DC系统时钟设置GEN1/GEN2
Drawing DEM with GEE gracefully
To open the registry
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
JMeter environment deployment
Instruction rearrangement concept
Xiaobai, let me ask you guys, is MySQL binlog extracted by CDC in strict order
Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi