类似于台球游戏,台球碰到桌台边缘会根据不同角度反弹,我用发射子弹的形式来模拟,而且屏蔽了子弹之间的碰撞
先看效果:
炮台也做了跟随鼠标点击旋转,共三个脚本
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RollControler : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
//计算角度
Vector3 mousePos = Input.mousePosition;
Vector3 clickPos = Camera.main.ScreenToWorldPoint(mousePos);
Vector2 dic1 = Vector2.down;
Vector2 dic2 = transform.position - clickPos;
Vector3 v3 = Vector3.Cross(dic1, dic2);
float angle = 0;
if (v3.z > 0)