背景:在Unity 3D中制作一个小游戏。这是一个自上而下的射手。我在isKinematic设置为false且不使用重力的情况下,在其刚体上使用MovePosition()函数移动播放器。
所需的行为:当播放器与场景中的障碍物发生碰撞时,我希望控制播放器的脚本停止尝试将其强制进入对象。
问题:游戏物体的刚体和碰撞器成功地阻止了玩家通过固体物体移动,但玩家有时会紧张,如果物体足够小,即使玩家的Y位置被锁定,玩家也会在物体上出现故障。
问:对于自上而下的射手来说,做球员移动的最好方法是什么?我应该使用NavMesh吗?rigidBody?
发布于 2020-05-30 20:32:05
这是我在自上而下的射击游戏中使用的代码,我希望这能有所帮助:)
代码-
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Shooting : MonoBehaviour
{
public Transform firePoint;
public GameObject bulletPrefab;
public float bulletForce = 20f;
// Update is called once per frame
void Update()
{
if (Input.GetButtonDown("Fire1"))
{
Shoot();
}
}
void Shoot()
{
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, firePoint.rotation);
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
}
}https://stackoverflow.com/questions/45472970
复制相似问题