2D 游戏 - 如何立即反射球? [英] 2D Gaming - How to reflect a ball off the bat?

查看:52
本文介绍了2D 游戏 - 如何立即反射球?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 XNA 很陌生 &游戏开发者并停留在球反射上.我的球一旦击中球棒就会反射,但只在一个角度反射,无论球棒处于哪个角度.

I am pretty new to XNA & game dev and stuck at ball reflection. My ball is reflecting once it hits the bat, but only in one angle, no matter which angle the bat is at.

代码如下:

if (BallRect.Intersects(BatRect))
    {
        Vector2 NormBallVelocity = Ball.velocity;
        NormBallVelocity.Normalize();
        NormBallVelocity = Vector2.Reflect(Ball.velocity, NormBallVelocity);
        Ball.velocity = NormBallVelocity;
    }

球正在退回.如何让球看起来像是从球棒上反射出来的?

The ball is retracting its way back. How do I make it look like the ball is reflecting off the bat?

我看过其他帖子,但它们是 3D 方面的,我太新了,无法将其转换为 2D 术语...

I have seen other posts but they are on 3D front I am too new to translate it to 2D terms...

推荐答案

我很确定你需要反射蝙蝠的法线而不是球的速度,这是正常的.

I'm pretty sure you need to reflect off the bat's normal instead of the ball's velocity and it's normal.

这篇关于2D 游戏 - 如何立即反射球?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆