3D等距游戏Unity-弹丸跟随玩家运动
我试图用巫师射击火球制作3D等距游戏。我设法使它射击了火球,但它们朝着巫师面对的方向前进:如果我旋转巫师,火球会改变方向。我能做些什么?感谢您帮助我。 这是我制作的脚本(附加到播放器):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WizardController : Characters
{
[SerializeField]
public Transform spawnMagic;
private GameObject magicShot;
public List<GameObject> magicBullets = new List<GameObject>();
private void Start()
{
maxHP = 150.0f;
magicShot = magicBullets[0];
}
void Update()
{
GetInputs();
Attack();
Defend();
cameraFollow();
}
private void FixedUpdate()
{
LookAt();
Move();
}
public override void Attack()
{
if (Input.GetButtonDown("Fire1"))
{
GameObject magicBullet;
isAttacking = true;
GetComponent<Animator>().SetBool("hit1", true);
if (spawnMagic != null)
{
magicBullet = Instantiate(magicShot, spawnMagic.transform.position, Quaternion.identity);
}
}
else
{
GetComponent<Animator>().SetBool("hit1", false);
}
}
}
子弹的运动脚本是一个简单的“转换”行:
transform.position.posity.posity += spawnmagic.forward *(speed * time.deltatatime); << /code>
,这就是当玩家拍摄时发生的事情:
I'm trying to make a 3D Isometric game with a wizard shooting fireballs. I managed to make it shoot the fireball but they go in the direction which the wizard is facing: if I rotate the wizard the fireballs change direction. What can I do? Thanks for helping me.
This is the script I made (attached to the player):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WizardController : Characters
{
[SerializeField]
public Transform spawnMagic;
private GameObject magicShot;
public List<GameObject> magicBullets = new List<GameObject>();
private void Start()
{
maxHP = 150.0f;
magicShot = magicBullets[0];
}
void Update()
{
GetInputs();
Attack();
Defend();
cameraFollow();
}
private void FixedUpdate()
{
LookAt();
Move();
}
public override void Attack()
{
if (Input.GetButtonDown("Fire1"))
{
GameObject magicBullet;
isAttacking = true;
GetComponent<Animator>().SetBool("hit1", true);
if (spawnMagic != null)
{
magicBullet = Instantiate(magicShot, spawnMagic.transform.position, Quaternion.identity);
}
}
else
{
GetComponent<Animator>().SetBool("hit1", false);
}
}
}
The movement script for the bullet is a simple "transform.position" line:
transform.position += spawnMagic.forward * (speed * Time.deltaTime);
And this is what happen when the player shoot:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要解决这个问题,您必须使子弹运动独立于向导的任何对象 或依赖它转移。
如果您小心,
SpawnMagic
在向导移动时旋转,并且子弹由spawnmagic.forward
引用。首先,您需要将子弹旋转与生产过程中的产卵旋转相同。
然后,用移动部位的本地子弹向前替换
spawnmagic.forward
,它将使子弹运动在移动阶段的统计中置于SpawnMagic方向:To solve this problem, you must make the bullet movement independent of the any objects that are
Child
of wizard or depend on it transfrom.If you are careful, the
spawnMagic
rotates as the wizard moves, and the bullet is referenced byspawnMagic.forward
.First you need to place bullet rotation same as spawn spawnMagic rotation during production.
Then replace
spawnMagic.forward
with local bullet forward at movement part, it will make bullet movement indepent of spawnMagic direction during move phase: