[英]LibGDX Java set velocity at an angle
I have a problem with setting the velocity for a Body object at a certain angle (I want the body to move in a straight line at a given speed at a certain angle).我在将 Body 对象的速度设置为某个角度时遇到问题(我希望身体以给定的速度在某个角度沿直线移动)。 The Body#setLinearVelocity method requires the X and Y directions.
Body#setLinearVelocity 方法需要 X 和 Y 方向。 I don't know how to get these values from an angle (form -180 to 180 degrees).
我不知道如何从一个角度(从 -180 到 180 度)获取这些值。 I will be grateful for your help!
我将不胜感激您的帮助!
To convert an angle to coordinates (of length 1) you can use this:要将角度转换为坐标(长度为 1),您可以使用以下命令:
// angle needs to be in radians. If it's in degrees multiply it by Math.PI / 180f
angle = angleDegree * Math.PI / 180f;
x = Math.cos(angle);
y = Math.sin(angle);
Then add these parameters to the setLinearVelocity
method.然后将这些参数添加到
setLinearVelocity
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.