/// <summary> /// 设置直线运动参数 /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int STGMovableSetStraightParas(ILuaState luaState) { ISTGMovable movableObject = luaState.ToUserData(-6) as ISTGMovable; float v = (float)luaState.ToNumber(-5); float angle = (float)luaState.ToNumber(-4); bool isAimToPlayer = luaState.ToBoolean(-3); float acce = (float)luaState.ToNumber(-2); float accAngle; if (luaState.Type(-1) == LuaType.LUA_TBOOLEAN && luaState.ToBoolean(-1) == true) { accAngle = angle; } else { accAngle = (float)luaState.ToNumber(-1); } if (isAimToPlayer) { Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition(); float relAngle = MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition()); angle += relAngle; accAngle += relAngle; } movableObject.SetStraightParas(v, angle, acce, accAngle); return(0); }
/// <summary> /// 做加速运动 /// <para>movableObject 运动的物体</para> /// <para>float acce 加速度</para> /// <para>float angle 速度方向 or bool useVAngle使用速度方向</para> /// <para>bool isAimToPlayer 是否朝向玩家</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int STGMovableDoAcceleration(ILuaState luaState) { ISTGMovable movableObject = luaState.ToUserData(-4) as ISTGMovable; float acce = (float)luaState.ToNumber(-3); float angle = luaState.Type(-2) == LuaType.LUA_TBOOLEAN ? movableObject.vAngle : (float)luaState.ToNumber(-2); bool isAimToPlayer = luaState.ToBoolean(-1); if (isAimToPlayer) { Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition(); angle += MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition()); } movableObject.DoAcceleration(acce, angle); return(0); }
/// <summary> /// 做直线运动 /// <para>movableObject 运动的物体</para> /// <para>float v 速度</para> /// <para>float angle 速度方向</para> /// <para>bool isAimToPlayer 是否朝向玩家</para> /// </summary> /// <param name="luaState"></param> /// <returns></returns> public static int STGMovableDoStraightMove(ILuaState luaState) { ISTGMovable movableObject = luaState.ToUserData(-4) as ISTGMovable; float v = (float)luaState.ToNumber(-3); float angle = (float)luaState.ToNumber(-2); bool isAimToPlayer = luaState.ToBoolean(-1); if (isAimToPlayer) { Vector2 playerPos = PlayerInterface.GetInstance().GetCharacter().GetPosition(); angle += MathUtil.GetAngleBetweenXAxis(playerPos - movableObject.GetPosition()); } movableObject.DoStraightMove(v, angle); return(0); }