旋转游戏对象
Rotating a game object
在我的 javascript / BABYLON 游戏中,我想相对于对象所在的位置旋转对象。我有一个 table,周围有四把椅子。我创建了这个方法,它接受一个整数作为参数,并根据该值设置角色在 Y 方向的旋转。
/**
* Rotates the player in Y
* @param rotY The rotation to rotate the player in the y-axis (in radians)
*/
public rotatePlayer_Radians(rotY: number): void {
var bot = this.gameObject;
var rotY_Radians: number = BABYLON.Tools.ToRadians(rotY);
bot.meshObject.rotation.y = rotY_Radians;
}
我正在用另一种方法调用它:
/**
* Makes the player sit down in a chair
*/
private _sitOnChair(chairObj: MuveBabylon.GameObject): void {
//Rotate the player to the chair position
this.rotatePlayer_Radians(chairRot.y);
}
但是结果是角色坐着的时候总是面向一个方向。从上往下看它总是面朝上,就好像它总是坐在最下面的椅子上一样。
rotatePlayer_Radians(rotY: number): 听起来这个函数要求弧度,那你为什么要在函数本身中再次将参数转换为弧度?
在我的 javascript / BABYLON 游戏中,我想相对于对象所在的位置旋转对象。我有一个 table,周围有四把椅子。我创建了这个方法,它接受一个整数作为参数,并根据该值设置角色在 Y 方向的旋转。
/**
* Rotates the player in Y
* @param rotY The rotation to rotate the player in the y-axis (in radians)
*/
public rotatePlayer_Radians(rotY: number): void {
var bot = this.gameObject;
var rotY_Radians: number = BABYLON.Tools.ToRadians(rotY);
bot.meshObject.rotation.y = rotY_Radians;
}
我正在用另一种方法调用它:
/**
* Makes the player sit down in a chair
*/
private _sitOnChair(chairObj: MuveBabylon.GameObject): void {
//Rotate the player to the chair position
this.rotatePlayer_Radians(chairRot.y);
}
但是结果是角色坐着的时候总是面向一个方向。从上往下看它总是面朝上,就好像它总是坐在最下面的椅子上一样。
rotatePlayer_Radians(rotY: number): 听起来这个函数要求弧度,那你为什么要在函数本身中再次将参数转换为弧度?